In my previous post, i discussed how both protocols AMQP and MQTT could be of use for different enterprise requirements. Both protocols has its own advantages, in my opinion AMQP could be more robust over MQTT due to its maturity, however MQTT would outperform AMQP to its lightweight nature making the protocol more suitable for applications intended to be executed in low powered and constrained network environments.
Due to the potential of both the protocols the apparent question would be the possibility of using both of them. Could this be achieved ? the simple answer would be yes. The following post would discuss in a series on how this could be achieved using both WSO2 ESB and MB.
Transistor is typically used to switch electronic signals (typically between hight powered circuits to low powered once) i would like to apply that term to describe how WSO2 Enterprise Service Bus could act as a transistor to allow switching between both the protocols (AMQP protocol and MQTT) supported by WSO2 Message Broker, imagining the use case of an enterprise having AMQP as the high powered source and MQTT as the lightweight source deployed on devices running in constrained environments.
I would like to describe 4 patterns which could be followed when protocol switching,
- Publishing to a AMQP queue and receiving from MQTT topic consumer
- Publishing to AMQP topic and receiving from both MQTT and AMQP topic consumers.
- Publishing to MQTT topic and receiving from AMQP queue consumer
- Publishing to MQTT topic and receiving from AMQP topic consumer
The above patterns would be described in a generic fashion which could be implied to various use cases,
- To send/receive AMQP messages via JMS we use apache JMeter.
- To send/receive MQTT messages we use MQTT Fx as the client.
- Enable MQTT Transport sender and receiver in the ESB.
- Enable JMS Transport sender and receiver in the ESB.
- Copy the MB client libraries from $MB_HOME/client-lib to $JMeter_HOME/lib/ext and also copy the client libraries to $ESB_HOME/repository/components/lib/
- Create the jndi.properties file and add the following to it. Make sure to track the url of the jndi file location. This location should be replaced in the ‘Provider URL’ of the jmeter script file. The jndi file could be found in jndi.properties.
- Startup MB server. Make sure the MB server is running on its default offset.
- Startup ESB server. Make sure that you offset the ESB by 1.
1.0 AMQP Queue to MQTT Topic
Usage : Publishing message to AMQP Queue and consuming the message from MQTT client.
Use Case : This sample demonstrates how a message published to AMQP queue via JMS could be consumed by an MQTT consumer.
- Start the ESB server and log into its management console UI (https://localhost:9443/carbon). In the management console, navigate to the main menu and click source view in the service bus section. Next, copy the configuration which could be found in ESBConfiguration.xml .
- Replace the jndi.properties file which could be located in the ESB ($ESB_HOME /repository/conf) directory with jndi.properties.
- Start JMeter and import the script file AMQPQueuePublisher.jmx.
- Start MQTT fx client and subscribe to the topic ‘LocationTrackerTopic’.
- Execute the Jmeter script and observe.
The JMS message which was published to the LocationQueue should be received by the MQTT client consumer who is subscribed to LocationTrackerTopic.
As illustrated below in the screenshots,
JMS Client (JMeter)
MQTT Client (MQTT Fx)
Next post would describe the pattern of having AMQP topic producer distributing messages to both AMQP and MQTT consumers.