HTTP is the most popular and widely used protocol. But over the years MQTT quickly gained credibility in the IoT market.
IoT application developers are having to choose between these two protocols HTTP or MQTT.
MQTT is data centric while HTTP is document centric. HTTP is a request-response protocol for client computers and is not always optimized for mobile devices. The main benefits of MQTT are compactness (MQTT transfers data as a byte array) and publisher/subscriber model, making it perfect for resource-constrained devices and helping to save energy.
Besides, the publisher / subscriber model provides customers with independent existence and improves the reliability of the whole system. When one customer is inactive, the entire system can continue to function normally.
According to measurements in 3G networks, the throughput of MQTT is 93 times faster than HTTP.
In addition, compared to HTTP, the MQTT Protocol guarantees the highest quality of delivery.
There are 3 levels of Quality of Service (Qos):
MQTT also provides users with options for final and retained messages. This means that in the event of an unexpected client disconnection, all subscribed clients will receive a message from the broker.
Retained messages mean that a new customer subscriber will receive an immediate status update.
The HTTP protocol does not have these capabilities.
MQTT has a pretty short specification. Only the CONNECT, PUBOUND, SUBSCRIBE, UNSUBSCRIBE and DISCONNECT types make sense to developers. While the HTTP spec is much longer.
When comparing the message size between MQTT and HTTP : MQTT has a very short message header and the smallest packet message size is 2 bytes. Using the text message format using the HTTP protocol allows it to compose long headers and messages.
This eliminates the hassle as it is human readable, but at the same time, it is not necessary for devices that are resource constrained and only need to pass binary parameters.
The following table compares the MQTT and HTTP protocols.
Features and characteristics | MQTT | HTTP |
Complete forms | Message queuing remotely | Hypertext Transfer Protocol |
Design method | Protocol is data center | Protocol is the central document |
Architecture | Publisher / Subscriber: Here devices can publish any topic and also subscribe to any updated topic. | Request/Response |
Complexity | Simple | More complex |
Data security | Have | Not yet secure, so HTTPS is used to provide security |
Upper layer protocol | Runs on TCP | Run on UDP |
Message size | Small, binary with header taking up 2 Bytes | Big, in ASCIILarge format, print ASCII format |
Service Levels (QoS) | 3 | 1 |
Library | 30KB C, 100KB Java | Big |
Port | 1883 | 80 or 8080 |
Data partition | 1 to 0/1/N | one to one |
The MQTT protocol is very easy to use, responds well to unstable connection conditions, and low bandwidth. This makes MQTT very suitable for IoT applications.
Thứ Hai - Thứ Sáu: 8:00 - 17:30
Thứ Bảy: 8:00 - 12:00
Thứ Hai - Thứ Sáu: 8:00 - 17:30
Thứ Bảy: 8:00 - 12:00