Table of Contents |
---|
Introduction
This sample demonstrates how the MQTT Connector connector publishes the a message on a particular topic and how the a MQTT client which that is subscribes subscribed to that topic receives it.
Prerequisites
...
Download and install the following before starting MQTT sample configurations.
- mqtt-client-0.4.0.jar
- mqtt-connector-1.0.0.zip
mosquitto-1.3.4 (http://mosquitto.org/)
Building the Configuration
For Consumer ESB
Download wso2esb-4.9.0-BETA-SNAPSHOT and do the following configuration changes.
...
- Start the MQTT-supported server. (E.g. Mosquitto)
Building the sample
For consumer ESB
- Copy the following client libraries to the
<
ESB_HOME>/repository/components/lib
...
- axis2-transport-mqtt-1.0.0.jardirectory.
- mqtt-client-0.4.0.jar
- mqtt-client-0.4.0.jar
Add the XML configuration for the inbound endpoint as follows:
Code Block language xml title Insequence <inboundEndpoint xmlns="http://ws.apache.org/ns/synapse" name="test" sequence="TestIn" onError="TestIn" protocol="mqtt" suspend="false"> <parameters> <parameter name="sequential">true</parameter> <parameter name="mqtt.connection.factory">mqttFactory</parameter> <parameter name="mqtt.server.host.name">localhost</parameter> <parameter name="mqtt.server.port">1883</parameter> <parameter name="mqtt.topic.name">esb.test2</parameter> <parameter name="mqtt.subscription.qos">2</parameter> <parameter name="content.type">application/xml</parameter> <parameter name="mqtt.session.clean">false</parameter> <parameter name="mqtt.ssl.enable">false</parameter> <parameter name="mqtt.subscription.username">elil1</parameter> <parameter name="mqtt.subscription.password">e13</parameter> <parameter name="mqtt.temporary.store.directory">my</parameter> <parameter name="mqtt.blocking.sender">false</parameter> </parameters> </inboundEndpoint>
Code Block language xml title TestIn <sequence xmlns="http://ws.apache.org/ns/synapse" name="TestIn"> <log level="full"/> <drop/> </sequence>
For
...
publisher ESB
Download wso2esb-4.9.0-BETA-SNAPSHOT and do the following configuration changes.
Upload the mqtt-connector-1.0.0.zip to esb.
Add the following proxy and local entries.
Code Block | ||||
---|---|---|---|---|
| ||||
<proxy xmlns="http://ws.apache.org/ns/synapse" name="mqttXML" transports="https http" startOnLoad="true" trace="disable">
<description/>
<target>
<inSequence>
<property name="msg" expression="//msg"/>
<mqtt.publish configKey="xxx">
<topic>esb.test2</topic>
<qos>2</qos>
<msg>{$ctx:msg}</msg>
<retained>true</retained>
<disconnectAfter>false</disconnectAfter>
</mqtt.publish>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
</proxy> |
Code Block | ||||
---|---|---|---|---|
| ||||
<localEntry xmlns="http://ws.apache.org/ns/synapse" key="xxx">
<mqtt.init>
<hostName>localhost</hostName>
<port>1883</port>
<sslEnable>false</sslEnable>
<asyncClientEnable>true</asyncClientEnable>
<username>admin</username>
<password>0777</password>
<lwMessage>lwMSG</lwMessage>
</mqtt.init>
<description/>
</localEntry> |
If you want to use the mosquito publisher you can start simply by typing the following in the console.
...
Run the following command to use the mosquito publisher:
Code Block |
---|
mosquitto_pub -h 127.0.0.1 -t esb.test2 -m "<msg><a>Testing123</a></msg>" |
Executing the
...
request
Now once you are done with the configurations start the consumer and publisher ESBs. Start the mosquitto subscriber using After you perform the required configuration changes,
- Start the ESB and the mosquito publisher.
Start the mosquitto subscriber by executing the following command:
Code Block mosquitto_sub -h 127.0.0.1 -t esb.test2
Then give the following request to the proxy endpoint.
...
Analyzing the output
On the console you can will see the following.
: