Publish Subscribe (pubsub) messaging is becoming crucial for distributed and connected systems. There are a couple of protocols and solutions implementing pubsub, but it is not straightforward to decide which one to use. In this post, we give a short summary of what is available and share a little bit of our experiences with them.
The growth of smart phones and the fast development of the internet of things has lead to a substantial increase of the number of devices connected to the internet, producing and consuming data towards internet based services. Together with that, internet connectivity is becoming more and more pervasive due to the drop of prices and sizes of network adapters on the devices side; and drop of price and increase of coverage and bandwidth on the network provider’s side.
As more data gets exchanged in internet services and clients require to get this data as soon as it is published, more applications are built following the Observer Pattern and systems are built based on communication protocols that support the Publish Subscribe (pubsub) pattern . There are a few different communication protocols and implementations supporting pubsub, such as AMQP, XMPP, MQTT and pubsubhubbub to name a few. In recent projects SIT has been involved, we have worked both with XMPP and MQTT.
The eXtensible Messaging and Presence Protocol (XMPP) is a communication protocol which was initially developed for supporting instant messaging (IM) applications such as ICQ, MSN and Jabber.org. Jabber.org was actually the basis for XMPP. Being developed for IM systems, XMPP natively supports instant messaging (IM), presence information and contact list maintenance. However, due to the openness and extendibility of the protocol, XMPP has been extended to support multi-user chat, service discovery, pub-sub and voice communication signaling.
MQTT, MQ Telemetry Transport, is a protocol created by IBM, with the roots, as the name says, on telemetry. Just like XMPP, the MQTT also runs on top of TCP/IP and supports pub-sub. However, MQTT has been intended to be used by small devices. That means that Mqtt it is more lightweight, less verbose. It has a minimalistic message header and binary payload in contrast to the xml based messaging format of XMPP.
Overall, both protocols seem more suitable to application around what they are intended to cover: XMPP for user/social centric applications (taking advantage of the several social and user communication based extensions) and MQTT for device centric communication (taking advantage of the small payload and with less importance given to the identity of the peer).
Both technologies have covered the server or broker aspects with open source software supported by strong communities. But when it comes to android libraries for clients, the support is more limited.
|Protocol||Client Android Libraries||Open source servers or brokers||Renown services using it|
|XMPP||Asmack and Jaxmpp2||Openfire and Ejabberd||Google Talk, Google Plus, Apache Wave|
|MQTT||Paho and mqqt fusesource||Mosquittto , Apache Activemq, Activemq Apollo||Facebook messenger|
XMPP counts with 2 popular libraries, where perhaps the most popular one is the Asmack, the android port of the smack library. We have not worked with Asmack, bur our colleagues in the Societies project had. We remember some of them mentioning that the library was not that stable a year ago. However, there has been many commits since then, so hopefully the library has gotten better with time. There are also many examples and tutorials (such as this one from Samsung) on how to get started with XMPP on Android, or alternatively you can dive into the XMPP client code developed in Societies.
When it comes to MQTT, we have had some developing experience with it thanks to the Aniketos project. There, we built an open source Mqtt client Android application that would receive security notifications modeled as MQTT messages published to MQTT topics. While part of the code of the application is very specific to Aniketos, the management of the MQTT connection and publish/subscribing have been implemented as an Android Service and can be easily re-used in other projects communicating through MQTT. We used the mqtt fusesource library since the paho was not available at the time we started. Both libraries are relatively new and we have not submitted the fusesource one to any stress that could validate it for usage in a production application. However, it worked fine in our prototype application.
Have you had any experience with MQTT or XMPP that you want to share? Do you want to contribute or make use of the code we have produced? Drop us a line.