Direct MQTT vs MQTT over WebSocket [closed]

Solution 1:

You should only need to run MQTT over websockets if you intend to publish/subscribe to messages directly from within webapps (in page).

Basically I would run pure MQTT for everything and only add the websockets if you actually need it.

For all the non-browser languages the MQTT client libraries only use native MQTT. For Javascript there is both a pure MQTT library and the Paho in page library that uses websockets.

Edit: The firewall tunnelling use case is a valid reason to use MQTT over websockets and since writing this answer more of the none web/JavaScript client libraries have added support

Solution 2:

Two main reasons for using MQTT over Websockets (which effectively means going over HTTP/HTTPS):

  • Web apps (those running in a browser - e.g. written in JavaScript)
  • Any other applications that don't want to use the 1883/8883 port and want to go over HTTP/HTTPS instead - this could be so that there is less of a chance of being blocked by a firewall (e.g. in a corporate network), as most firewalls will let HTTP traffic through

If you don't need or worry about the above, use "direct" MQTT:

  • it is more efficient
  • there are more client libraries for various languages that work with "direct" MQTT

Solution 3:

MQTT is a protocol which supports following:

  • Provides publish/subscribe mechanism
  • Quality of Service policy
  • Have minimal overhead in communication
  • Specifically designed for narrowband communication channel and
    constrained devices.

Depending upon the device there is an implementation available.

Browser : It uses websockets. Websocket provides browsers with a capability to establish a full duplex communication. There is Javascript library to implement MQTT functionality, see Eclipse Paho JavaScript Client

Android : Their is a MQTT client library written in Java for developing applications on Android. See Eclipse Paho Android Service

So it depends on device that is going to use this functionality. For standards and specifications please visit MQTT Version 5.0

Hoping this helps.

Cheers !

Solution 4:

MQTT over websockets is perfect if ever a certain webpage is the sending or the receiving MQTT client.

A good summary of the capabilities of MQTT over websockets can be found here.