Using MQTT Protocol Advantages Over HTTP in Mobile Application Development
Kathleenholm 2700009BHX Comment (1) Visits (12633)
In the mobile environment, response times, throughput, lower battery use and lower bandwidth are key design criteria. Compared with HTTP, MQTT features faster response and throughput, and lower battery and bandwidth usage, making it well suited to use cases where:
· connectivity is intermittent
· bandwidth is at a premium
· an enterprise application needs to interact with one or more phone apps
· phone or tablet apps need to send data reliably without requiring code retry logic
Basically, MQTT is designed for low latency, assured messaging and efficient distribution. HTTP is not optimized for low power usage or minimizing the amount of bytes flowing. In one test, conducted by Stephen Nicolas,
“…you’d save ~4.1% battery per day just by using MQTT over HTTPS to maintain an open stable connection.
The reason for this is simple. While it costs MQTT more to create the initial connection, this is essentially a one off and the cost of the following keep alives is comparatively small. Whereas for HTTPS it needs to perform the ‘expensive’ connection stage every time it has to reconnect (up to once each keep alive interval, in my implementation).
As this testing has shown, MQTT uses less power to maintain an open connection, to receive messages and to send them. It also does these last two more quickly and reliably. The only place where it loses out is in establishing the initial connection (with cleanstart=true) and that’s mitigated after ~5 ½ minutes of being connected.”
Other advantages built into the MQTT protocol are retained messages and multiple subscriptions ‘multiplexed’ over one connection.
So What for Developers?
So what does this mean to you? If battery consumption is a key design criteria, then MQTT is the clear answer. If you have an enterprise application pushing to a mobile device, MQTT is the easiest answer. And if you’re already working with Worklight, MQTT is built-in, so you don’t need to learn new technology. HTTP is venerable, extendable and useful. But MQTT beats it for most mobile application development.
For more information:
Read the article (contains sample code), “Using MQ Telemetry Transport Protocol in IBM Worklight Mobile Applications”.
IBM WebSphere MQ Download.