Sample 906: Inbound Endpoint MQTT Protocol Sample
Note that WSO2 EI is shipped with the following changes to what is mentioned in this documentation:
<PRODUCT_HOME>/
repository/samples/
directory that includes all Integration profile samples is changed to<EI_HOME>/
samples/service-bus/
.<PRODUCT_HOME>/
repository/samples/resources/
directory that includes all artifacts related to the Integration profile samples is changed to<EI_HOME>/
samples/service-bus/resources/
.
Introduction
This sample demonstrates how the MQTT connector publishes a message on a particular topic and how a MQTT client that is subscribed to that topic receives it. You can try this sample using the following message brokers:
Using Mosquitto as the Message Broker
Following sections demonstrate how you can try this sample using the Mosquitto server as the Message Broker.
Prerequisites
Follow the steps below before starting the MQTT sample configurations.
- Download and install WSO2 EI. For instructions, see /wiki/spaces/EI6xx/pages/49616415.
- Download and install Mosquitto. (This sample is tested for Mosquitto1.4.3 version.)
- Download MQTT client library (i.e.
mqtt-client-0.4.0.jar
) and add it to the<EI_HOME>/lib/
directory.
Building the sample
- Start the MQTT-supported server. (E.g. Mosquitto)
- Execute the following command to prepare Mosquitto server for the launch:
ln -sfv /usr/local/opt/mosquitto/*.plist ~/Library/LaunchAgents
- Execute the following command to run the Mosquitto server:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mosquitto.plist
- Execute the following command to prepare Mosquitto server for the launch:
Open a new Terminal and start the ESB profile of WSO2 EI. For instructions, see Starting the ESB Profile.
Log in to the Management Console, and click Main → Inbound Endpoints → Add inbound Endpoint.
Enter a name for the Inbound Endpoint (e.g.,
SampleInbound
), select MQTT as the type, and click Next.
Enter the following details, and click Save.
- Sequence:
TestIn
- Error Sequence:
fault
- coordination:
false
- mqtt.connection.factory:
mqttConFactory
- mqtt.server.host.name:
localhost
- mqtt.server.port:
1883
- mqtt.topic.name:
esb.test
- Sequence:
Click Main → Sequences → Add Sequence.
Enter the name of the Sequence as
TestIn
.Construct the following sequence.
Click Save & Close.
Executing the sample
In a new Terminal window, execute the following command to publish a message using the Mosquitto publisher.
mosquitto_pub -t esb.test -m "<msg><a>Testing123</a></msg>"
Analyzing the output
You view the ESB profile receiving the messages in the logs of it in the Terminal as shown below.
Using Broker Profile as the Message Broker
Following sections demonstrate how you can try this sample using the Broker profile of WSO2 EI as the Message Broker.
Prerequisites
Follow the steps below before starting this MQTT sample configurations.
- Download and install WSO2 EI. For instructions, see /wiki/spaces/EI6xx/pages/49616415.
- Download MQTT client library (i.e.
mqtt-client-0.4.0.jar
) and add it to the<EI_HOME>/lib/
directory.
Building the sample
Start the Broker profile of WSO2 EI. For instructions, see Starting the product profiles - Broker profile.
Start the ESB profile of WSO2 EI. For instructions, see Starting the product profiles - ESB profile.
Log in to the Management Console, and click Main → Inbound Endpoints → Add inbound Endpoint.
Enter a name for the Inbound Endpoint (e.g.,
SampleInbound
), and click Next.
Enter the following details, and click Save.
When creating the below Inbound Endpoint, specify the value of mqtt.server.port as 1886 because the Broker profile starts with a default port offset of 3 in WSO2 EI.
- Sequence:
TestIn
- Error Sequence:
fault
- coordination:
false
- mqtt.connection.factory:
mqttConFactory
- mqtt.server.host.name:
localhost
- mqtt.server.port:
1883
- mqtt.topic.name:
esb.test
- Sequence:
Click Main → Sequences → Add Sequence.
Enter the name of the Sequence as
TestIn
.Construct the following sequence.
Click Save & Close.
Executing the sample
In a new Terminal window, execute the following command to publish a message using the Mosquitto publisher.
mosquitto_pub -t esb.test -m "<msg><a>Testing123</a></msg>"
Analyzing the output
You view the ESB profile receiving the messages in the logs of it in the Terminal as shown below.