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.
- WSO2 MB 3.1.0 or mosquitto MQTT broker (http://mosquitto.org/)
Building the sample
- Copy the eclipse Paho MQTT client jar to the
<ESB_HOME>/repository/conf/axis2/axis2.xmlfile and change the MQTT sender and listener configuration to be as follows:
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_HOME>/repository/conf/carbon.xmlfile and set the offset to 1 as follows:
- Start WSO2 MB, open the Management Console and create a topic named esb.test2.
Start the ESB with the sample 272 configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration. The XML configuration for this sample is as follows:
This configuration file
synapse_sample_272.xmlis available in the
Executing the sample
Execute the following command to start the MQTT subscriber on the esb.test2 topic:
Execute the following command to run the MQTT publisher to publish to the esb.test1 topic:
Analyzing the output
When you analyze the output messages on the MQTT subscriber console, you will see the following log: