
上QQ阅读APP看书,第一时间看更新
Advantages to MQTT
- Packet agnostic: Any type of data can be transported in the payload carried by the packet. The data could be text or binary. It does not matter as long as the receiving party knows how to interpret it.
- Reliability: There are some Quality of Service (QoS) options that can be used to guarantee delivery.
- Scalability: The publish/subscribe model scales well in a power-efficient way.
- Decoupled design: There are several elements to the design that decouple the device and the subscribing server, which result in a more robust communication strategy.
- Time: A device can publish its data regardless of the state of the subscribing server. The subscribing server can then connect and receive the data when it is able. This decouples the two ends of the communication on a time basis. Think of it like the ability to text someone on your phone. He can reply whenever he gets the chance. If you called him, he would have to be available to talk at the same time as you are. If you both are busy in meetings all day, you end up trading voicemails and the communication slows. This allows the devices to remain in sleepy states without having to worry about if the subscriber is able to receive the data at the time the device wakes up to communicate.
- Space (delivery details): The publisher needs to know the broker IP address and how to communicate with it, but it does not need to know anything about the subscribers. Subscribers do not need to know the network connection details of the publisher. This keeps the communication overhead low on the device side (usually much more constrained in terms of power availability). It also allows both ends to operate independently. The subscriber can be changed or upgraded and additional subscribers added with no change needed on the publishing device end.
- Synchronizing: Neither side has to pause what they are doing to communicate or receive a message. The process is asynchronous. There is no need to interrupt work in progress to publish a message.
- Security: This is in both the advantage and disadvantage lists. You can have security with MQTT, which is why it is on the advantage list. Since MQTT operations over TCP, you can and absolutely should use the TLS/SSL encryption in the communication. But MQTT is natively unencrypted, which is why it is also in the disadvantage list - more about this will be explained later.
- Bidirectional: A device can be both a publisher and a subscriber. In this way, it can receive commands by subscribing to a topic on the broker. It could also receive data from other devices that could be an input into the data it publishes. In practice, a hub and spoke model is typically the case.
- Maturity: MQTT was invented by IBM with the first draft of the protocol in 1999 based on its MQSeries product (this is where the message queue part of the name comes from). It was released royalty free in 2010 and has since been donated as an open source project to the Eclipse foundation. It is in use by millions of connected products.