This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

MQTT Inbound Protocol

MQ Telemetry Transport (MQTT) is a lightweight broker-based publish/subscribe messaging protocol, designed to be open, simple, lightweight and easy to implement. These characteristics make it ideal for use in constrained environments.

For example, 

  • When the network is expensive, has low bandwidth or is unreliable.

  • When running on an embedded device with limited processor or memory resources.

To configure the MQTT inbound endpoint, you need to specify XML fragments that represents various parameters.

Following is a sample MQTT inbound endpoint configuration that can subscribe to messages using the specified topic:

<inboundEndpoint xmlns="http://ws.apache.org/ns/synapse" name="Test" sequence="TestIn" onError="fault" 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">ei.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">client</parameter>
      <parameter name="mqtt.subscription.password">e13</parameter>
      <parameter name="mqtt.temporary.store.directory">m1y</parameter>
      <parameter name="mqtt.reconnection.interval">5</parameter>
   </parameters>
</inboundEndpoint>

MQTT inbound endpoint parameters

Parameter

 

Description

 

Required

 

sequential
The behaviour when executing the given sequence.Yes
coordination
In a cluster setup, if set to true, the inbound endpoint will run only in a single worker node. If set to false,  it will run on all worker nodes.Yes
suspend
If set to true, the inbound listener will not accept incoming request messages from clients and will not inject messages to the synapse message mediation. If set to false, incoming messages will be accepted.Yes
mqtt.connection.factory
Name of the connection factory.Yes
mqtt.server.host.name

Address of the message broker (eg., localhost).

Yes
mqtt.server.port
Port of the message broker (e.g., 1883).Yes
mqtt.topic.name
MQTT topic to which the message should be published.Yes
mqtt.subscription.qos
The quality of service level that need to be maintained with the subscription. The quality of service level can be either 0,1 or 2.
0 -  Specifying this level ensures that the message delivery is efficient. However, specifying this level does not guarantee that the message will be delivered to its recipient.
1 -  Specifying this level ensures that the message is delivered at least once, but this can lead to messages being duplicated.
2 - This is the highest level of quality of service. Specifying this guarantees that the message is delivered and that it is delivered only once. 
No
mqtt.client.id
The id of the client.No
content.type
The content type of the message. (i.e., XML or JSON)Yes
mqtt.session.clean

Whether the client and server should remember the state across restarts and reconnects.

No
mqtt.ssl.enable
Whether to use tcp connection or ssl connection.No
mqtt.subscription.username
The username for the subscription.No
mqtt.subscription.password
The password for the subscription.No
mqtt.temporary.store.directory

Path of the directory to be used as the persistent data store for quality of service purposes.

No
mqtt.reconnection.interval

The retry interval to reconnect to the MQTT server.

No

Samples

For a sample that 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, see Sample 906: MQTT Inbound Endpoint Sample.