Red Hat JBoss A-MQ and the IoT
Red Hat JBoss A-MQ and the IoT
Join the DZone community and get the full member experience.Join For Free
Digi-Key Electronics’ Internet of Things (IoT) Resource Center Inspires the Future: Read More
How to be a JBoss A-MQ and Android Rock Star in the world of the Internet of Things!
I wanted to pull together a simple example of how to leverage Red Hat JBoss A-MQ in the Internet of Things (IoT) through the use of Message Queue Telemetry Transport (MQTT) in Android.
The first part of the article will highlight the concepts and technologies used in the demonstration. The second part will get you up and running with an example in a couple of minutes just like a rock star. The example shows how easy it is to publish and subscribe to a topic in JBoss A-MQ from Android using the MQTT Client.
Part 1 - The Concepts
What is MQTT?
MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.
MQTT is now an open standard through OASIS. The first meeting of theOASIS MQTT Technical Committeewas held on 26 March 2013 in Boston as a F2F (Face 2 Face) meeting. A very good overview on MQTT from Dave Locke is in the references. 
What is Red Hat JBoss A-MQ?
The demonstration includes code from the Red Hat JBoss Fuse MQTT Client library that Hiram Chirino started. The library supports Blocking, Future and Callback/Continuation Passing Based APIs. The source is located in the references.  I included the library in the project. I also utilized the code from Jason Sherman for the sample Android Application.   In addition I utilized Eric Schabell's JBoss Rock Star template for a quick build of the demonstration. 
The only updates to the activemq.xml file that are required are:
1. The transport connector for mqtt. The standard port is 1883.
<transportConnectors> <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/> <transportConnector name="mqtt" uri="mqtt+nio://0.0.0.0:1883"/> </transportConnectors>
2. To enable security we just use the SimpleAuthenticationPlugin.
<plugins> <simpleAuthenticationPlugin> <users> <authenticationUser username="system" password="manager" groups="users,admins"/> <authenticationUser username="user" password="password" groups="users"/> <authenticationUser username="guest" password="password" groups="guests"/> </users> </simpleAuthenticationPlugin> </plugins>
The main code in the Android app is in the MQTTActivity.java file in the org.example.mqtt package. The android app UI is in the main.xml and can be seen in the graphical layout.
Part 2 - The demo
Steps to build and run the demo
1. Download the code from github at https://github.com/kpeeples/a-mq-android-mqtt
2. Download Red Hat JBoss A-MQ from https://www.jboss.org/products/amq.html and place in the installs directory.
3. Download the Android Bundle from http://developer.android.com/sdk/index.html and unzip.
4. Download and start JBoss Developer Studio 7 or the Fuse IDE.
5. Add the Android Developer Plugins
6. Create a Android Virtual Device (AVD) through JBDS in the Android Virtual Device Manager in the Window menu. If the Android Virtual Device Manager does not show on the Window menu then Click on Window > Customize perspective > Command Groups Availability tab. Check the "Android SDK and AVD Manager" option and hit the OK button.
7. Import the Android project in JBDS
8. Run the init.sh to setup A-MQ
9. Start A-MQ in the foreground by executing target/jboss-a-mq-6.0.0.redhat-024/bin/amq
10. Right click on AndroidManifest.xml and Run As Android.
11. Connect to the broker and make sure to use the IP instead of localhost and use a username/password entered from the activemq.xml
12. Enter a destination topic and a test message then click send
13. The message will sent to the topic, read from the topic and then placed in the received field.
Opinions expressed by DZone contributors are their own.