Suppose you are developing an application that is going to monitor the boundary fence of a wild life sanctuary in Africa or you are developing a pollution monitoring system that will collect data on how much pollution is created by traffic during rush hours in the Netherlands. Both systems have one thing in common, in both systems we are dealing with a lot of sensors. These can be motion sensors or environmental sensors to detect the air quality. When working with sensors or IoT systems, we must handle communication very efficiently. This is because usually we have very limited resources in terms of storage, power and processing. This is where MQTT comes in.
Introduction to MQTT
MQTT refers to Message Queueing Telemetry Transport protocol. This protocol was designed to be an extremely light weight publish/subscribe messaging transport. It is useful for connections with remote locations where we can only use limited network bandwidth. MQTT is being used world wide and even Facebook messenger application also uses some aspects of the MQTT protocol to send notifications about new messages. MQTT protocol only works with publishing/subscribing model so in simple word you can only use it with Topics.
Introduction to MQ Series v8 (IBM WebSphere MQ)
IBM MQ is a family of message-oriented middleware products. It was originally launched in December 1993. At the time of launch it was referred as WebSphere MQ Series then in 2002 IBM renamed it as WebSphere MQ and in 2014 it again got renamed to IBM MQ.
Organizations use IBM MQ to enable applications to communicate at different times and in many diverse computing environments. In IBM MQ we first create Queue Managers. A queue manager act as a logical container to different sets of queues and topics. We can create Local Queues and Local Topics and expose them via JMS Protocol, MQTT, AMQP or IBM MQ own Rest base Interface. We can also create aliases and use them to send/receive messages instead of referring to the actual queue/topic. We will now see how we can enable MQTT transport in IBM MQ and then we will create a topic and expose it via a MQTT Channel.
Enabling MQTT Transport in IBM MQ Series v8
In order to verify that MQTT transport is enable in the IBM MQ or not, first launch the MQ Explorer. If you have already created a Queue Manager, then its ok otherwise create a new Queue Manager. Once the Queue Manager is created, expand its folder hierarchy as shown below and look for a folder name as “Telemetry”.
If you are not able to see this Telemetry folder, then don’t panic because it means that you haven’t installed it yet. Just run the MQ installer again and update the existing installation. You have to select the “Telemetry Service” and “Telemetry Clients” when you are doing the installation.
After restarting the Explorer, either go into your existing queue manager or create a new one. Expand the Queue Manager folder hierarchy from the left-hand side down arrow button and u will see the Telemetry folder. It means that we have successfully enabled the MQTT support in the IBM MQ.
Creating a Local Topic
To create a local topic, follow the following steps.
- Right click on the “Topic “option in the left-hand panel and select “New “and “Topic.
- Give the topic name as “testTopic”. Leve the other configuration as default.
- Provide a topic string and leave the other configurations as default. Use the same value as you mentioned in the earlier step i.e. “testTopic”.
- You can see that the topic is successfully created.
Creating a Telemetry Channel
Now we will create a telemetry channel. By which we can expose the Topic. To create that follow the following steps:
- Select the Telemetry option on the right-hand menu button and then select “New”and then “Telemetry Channel” option.
- Give the channel name as “esbChannel” and port as default.
- Select all the default options and finish the wizard.
- You can see the channel once the wizard is finished. You can also see the channel status is showing as “Running”.
Bridging the Gap using WSO2 EI
So far, we have successfully enabled the MQTT transport in IBM MQ. We have also create a local topic and then also created a MQTT Channel. We will now configure the WSO2 Enterprise Integrator to be able to subscribe to this topic and consume the message.
In WSO2 Enterprise Integrator you can enable the MQTT transport in following two ways:
- Axis2 Transport
- Inbound Endpoint
In this blogpost, we will do it via Inbound Endpoint. We have created one sequence LogMessageData which is just logging the message and then drops it. And we are using default fault sequence for this scenario. In WSO2 Enterprise Integrator do the following steps:
- Launch the WSO2 Enterprise Integrator
- Create a New Inbound endpoint and do the following configurations:
- You can see that we have provided the topic name as we have mentioned in the MQ Explorer. After filling in all the mandatory values, save the inbound endpoint.
- You can see the log in your WSO2 EI console that the inbound endpoint is successfully connected to the broker.
Let’s See if it Works???
To test this scenario, we will publish a message on the topic in IBM MQ explorer and the message will consumed by the WSO2 Enterprise Integrator. This will happen because EI has already subscribed to this topic. Once a new message is published, EI will pick it up. Let’s see how to test this scenario:
- Go to the “Topics” tab in the MQ Explorer and click on it.
- You will see all the topics in the MQ-Explorer-Content perspective window.
- Select the topic and right click on it. After that click on the “Test Publication” option.
- Type the data in the “Message Data” field and select “Publish message option.
- Go the ESB Console log and you will see the message consumed by your Sequence that you mentioned in the Inbound endpoint configuration.
- This means that connection between the IBM MQ Explorer and WSO2 Enterprise Integrator is successfully working.
What can we do Further?
We have seen in this example that how we can enable WSO2 Enterprise Integrator to connect to a message-oriented middleware like IBM MQ. We have also seen that how we can use MQTT transport with EI and make integrations where MQTT protocol is required. We can use any other broker instead of IBM MQ which uses MQTT also with the WSO2 EI. In this example we have seen the subscribing scenario with a Topic using MQTT. Similarly, with WSO2 Enterprise Integrator you can also publish the messages on an MQTT topic as well.
MQTT support in the WSO2 EI enables us to also integrate it with IoT devices. The IoT is already connecting computing devices, appliances, humans and other living beings through the internet. We can summarize this all in a very beautiful quote:
“Things Grow Stronger When You Integrate”.
Try this example scenario yourself and don’t hesitate to give your feedback or ask any questions in the comment section below.