Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Insert excerpt
Integration ESB Profile SamplesIntegration
ESB Profile Samples
nopaneltrue

...

This sample demonstrates how WSO2 ESB's MQ Telemetry Transport (MQTT) listener consumes messages from a MQTT topic, and how the MQ Telemetry Transport (MQTT) sender publishes messages to a MQTT topic.

Image Removed

Prerequisites

...

  1. Copy the org.eclipse.paho.client.mqttv3-1.1.0.jar file to the <ESB<EI_HOME>/repository/components/lib directory.
  2. Edit the <ESB<EI_HOME>/repository/conf/axis2/axis2.xml file and change the MQTT sender and listener configuration to be as follows:

    Code Block
    languagexml
    <transportReceiver class="org.apache.axis2.transport.mqtt.MqttListener" name="mqtt">
            <parameter locked="false" name="mqttConFactory">
                    <parameter locked="false" name="mqtt.server.host.name">localhost</parameter>
                    <parameter locked="false" name="mqtt.server.port">1883</parameter>
                    <parameter locked="false" name="mqtt.client.id">esb.test.listener</parameter>
                    <parameter locked="false" name="mqtt.topic.name">esb.test1</parameter>
            </parameter>
        </transportReceiver>
     
    <transportsender class="org.apache.axis2.transport.mqtt.MqttSender" name="mqtt">
    </transportsender>
  3. Start the MQTT broker. If you are using WSO2 MB as the MQTT broker, you should set the WSO2 ESB port offset to 1 before running the ESB. To set the port offset in WSO2 ESB, open the <ESB<EI_HOME>/repository/conf/carbon.xml file and set the offset to 1 as follows:

    Code Block
    languagexml
    <Offset>1</Offset>
  4. Start WSO2 MB, open the Management Console and create a topic named esb.test2.
  5. Start the ESB with the sample 272 configuration. For instructions on starting a sample ESB configuration, see  Starting the ESB with a sample configurationThe XML configuration for this sample is as follows:

    Code Block
    languagexml
    <definitions xmlns="http://ws.apache.org/ns/synapse">
        <proxy name="SampleProxy" transports="mqtt" startOnLoad="true" trace="disable">
            <description/>
            <target>
                <endpoint>
                    <address uri="mqtt:/SampleProxy?mqtt.server.host.name=localhost&amp;mqtt.server.port=1883&amp;mqtt.client.id=esb.test.sender&amp;mqtt.topic.name=esb.test2&amp;mqtt.subscription.qos=2&amp;mqtt.blocking.sender=true"/>
                </endpoint>
                <inSequence>
                    <property name="OUT_ONLY" value="true"/>
                    <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2" type="STRING"/>
                </inSequence>
                <outSequence>
                    <send/>
                </outSequence>
            </target>
            <parameter name="mqtt.connection.factory">mqttConFactory</parameter>
            <parameter name="mqtt.topic.name">esb.test1</parameter>
            <parameter name="mqtt.subscription.qos">2</parameter>
            <parameter name="mqtt.content.type">text/plain</parameter>
            <parameter name="mqtt.session.clean">false</parameter>
        </proxy>
    </definitions>
     

    This configuration file synapse_sample_272.xml is available in the <ESB<EI_HOME>/repositorysamples/samplesservice-bus directory.

Executing the sample

...