Overview
MQ Telemetry Transport (MQTT) is a lightweight protocol which publish/subscribe messages. IIB has its built-in MQTT server/broker and input/output nodes for processing MQTT messages.
You can create sample message flows to receive an MQTT message by using the MQTTSubscribe node to subscribe/consume one or more topics on an MQTT server/broker. You can publish an MQTT message by using the MQTTPublish node in your message flow to publish messages to a topic on an MQTT server/broker. In receiving and sending messages, the MQTT nodes behave like MQTT clients.
Steps to Configure the Built-In MQTT Pub/Sub Broker
The built-in MQTT broker/server is activated by default when an integration node starts on the default port 11883, and it is the default transport for the publication of operational/admin and business events by an integration node (without WebSphere MQ is installed and a queue manager is specified on the integration node) You can modify the configuration of the built-in MQTT broker by using the below mqsichangeproperties command .
Implementing MQTT Pub/Sub in message flow
Create a simple message flow, which uses the MQTTPublish node to publish the transformed message over given topic.
To publish the messages to built-in-MQTT broker, below are the mandatory basic properties of MQTTPublish which needs to be updated.
Client ID | Give unique name. MQTT broker identify the clients based on Client ID example: ‘MQTTPublish12’ |
Topic name | Give MQTT topic name on which messages need to be published example: ‘Sports/Basketball’ |
Host name | The host name where MQTT server is running. |
Port | Port number of MQTT server running on the host. |
Quality of service | The quality of service level for the delivery of MQTT messages. Valid values are 0 – At most once, 1 – At least once, and 2 – Exactly once. |
Once the above steps are completed we can push the message to MQ Input node, After unit of work complete transformed message are published on given topic.
Values used in poc:
Create a sample flow which uses the MQTTSubscribe node to subscribe/consume the messages from the MQTT topics.
Client ID | Give unique name. MQTT broker identify the clients based on Client ID example: ‘MQTTSUB’ |
Topic name | Give MQTT topic name on which messages need to be subscribed/consumed example: ‘Sports/Basketball’( Give the same topic name which was used in publish node) |
Host name | The host name where MQTT server is running. |
Port | Port number of MQTT server running on the host. |
Quality of service | The quality of service level for the delivery of MQTT messages. Valid values are 0 – At most once, 1 – At least once, and 2 – Exactly once. |
Now messages which are published from the MQTTPublish node are subscribed/consumed in this flow. Here we have achieved the Pub/sub model with the help of MQTT built-in-server/broker, without using Websphere MQ.
Subscribing to event message topics:
We can also subscribe to Event Message Topics through MQTT server. Before subscribing to the below different events, we need to enable them by executing mqsichangeproperites command.
- OperationalEvents,
- AdminEvents,
- BusinessEvents
Note: Whenever BusinessEvents are enabled for MQTT, we need to execute the below mqsicommand
mqsichangeflowmonitoring <NodeName> -c active -e <ServerName> -j
Below table will help to differentiate the Even group and its corresponding event type. This would be used to construct the topic for each Event messages.
Event group | Event type | Topic event_type |
OperationalEvents | Resource statistics (JSON) | Statistics/JSON/Resource |
Resource statistics (XML) | ResourceStatistics | |
Message flow statistics (JSON) | Statistics/JSON | |
Message flow statistics (XML) | StatisticsAccounting | |
Workload Management | WorkloadManagement | |
AdminEvents | Integration node status | Status/ExecutionGroup |
Integration server status | Status | |
Integration server configuration | Configuration/ExecutionGroup | |
BusinessEvents | Monitoring | Monitoring |
For an instance, when we enable the BusinessEvent for MQTT server, all business events are emitted in the below topic, to consume the event messages, we need to use this topic in MQTTSubscriber node to get the events and process them accordingly.
Where POC is Integration Node name, POC1 is Integration Server Name.
For AdminEvents of Integration Server Status
For AdminEvents of Integration Node Status
Wildcard Characters in Topics:
Below are the three-special character which has its special meaning in the topics. A topic can have any special character except this three.
- Topic level separator “/”.
- This separator character “/” is used to provide a structure to the topic space
- Multilevel wildcard “#”.
- This wildcard character “#” is used to match multi levels within a topic
- Example: IBM/IntegrationBus/POC/#
- The single-level wildcard “+”.
- This wildcard character “+” matches only one level up in the topic.
- Example: IBM/IntegrationBus/POC/Monitoring/+/+