MQTT vs HTTP | Difference between MQTT and HTTP protocols
This page compares MQTT vs HTTP and mentions difference between MQTT and HTTP protocols. It mentions functional difference between MQTT bridge and HTTP bridge.
Introduction: IoT devices can connect and communicate with IoT cloud core using two protocols viz. MQTT and HTTP. For communication with cloud core, IoT devices require MQTT bridge or HTTP bridge. This is configured in device registry during device creation.
What is MQTT Bridge ?
MQTT is standard publish/subscribe protocol which is used by embedded devices. It is also used as common M2M interactions. In this device connection is maintained and it uses full duplex TCP connection.
The figure-1 depicts simple MQTT protocol architecture (broker based).
Following are the features of MQTT protocol:
• It is over TCP.
• It uses SSL/TLS for security.
• There are many messages used in MQTT protocol such as CONNECT, PUBLISH, SUBSCRIBE, DISCONNECT etc.
• Username/Password is used in 'connect' message.
• It encrypts payload i.e. it is payload agnostic.
• 1883 port is used by MQTT protocol.
Following are the features of MQTT protocol.
• Lower usage of bandwidth
• Low latency
• High throughput
• Supports raw binary data
What is HTTP Bridge ?
HTTP is connectionless protocol in which connection is not maintained with cloud core. HTTP protocol sends requests and receive responses. Cloud core supports selected versions of the HTTP protocol.
The figure-2 depicts, HTTP connection between client (web user) and web server. It uses normal IP header for routing of packets and data are not encrypted before transmission.
Following are the features of HTTP protocol.
• It is light in weight.
• It causes few firewall issues.
• In HTTP protocol, binary data must be base64 encoded. This requires more CPU and network resources.
Tabular Difference between MQTT and HTTP
Both MQTT and HTTP bridges use public key device authentication and JWTs (JSON Web Tokens). JWT is transmitted in "password" field of "CONNECT" message in MQTT protocol where as JWT is transmitted in "Authorization" header of "HTTP Request" message. In both protocols, telemetry events are pushed to the cloud Publish/Subscribe. Following table mentions difference between MQTT and HTTP protocols.
|Full Form||Message Queue Telemetry Transport||Hyper Text Transfer Protocol|
|Design Methodology||The protocol is data centric.||The protocol is document centric.|
|Architecture||It has publish/subscribe architecture. Here devices can publish any topics and can also subscribe for any topics for any updates.||It has request/response architecture.|
|Data security||YES||NO, hence HTTPS is used to provide data security.|
|Upper layer protocol||It runs over TCP.||It runs over UDP.|
|message size||small, it is binary with 2Byte header.||Large, it is in ASCII format.|
|Device Connection Status||It is reported.||It is not reported.|
|Libraries||30KB C, 100KB Java||Large|
|Port number||1883||80 or 8080|
|Data distribution||1 to 0/1/N||one to one only|