MQTT是什么
MQTT stands for MQ Telemetry Transport. It is a publish/subscribe, extremely simple and lightweight messaging protocol, designed for constrained devices and low-bandwidth, high-latency or unreliable networks. The design principles are to minimise network bandwidth and device resource requirements whilst also attempting to ensure reliability and some degree of assurance of delivery. These principles also turn out to make the protocol ideal of the emerging “machine-to-machine” (M2M) or “Internet of Things” world of connected devices, and for mobile applications where bandwidth and battery power are at a premium.
MQTT是一个基于客户端-服务器的消息发布/订阅传输协议。MQTT协议是轻量、简单、开放和易于实现的,这些特点使它适用范围非常广泛。在很多情况下,包括受限的环境中,如:机器与机器(M2M)通信和物联网(IoT)。其在,通过卫星链路通信传感器、偶尔拨号的医疗设备、智能家居、及一些小型化设备中已广泛使用。2014年发布的MQTT v3.1.1
是当前MQTT协议的最新版本。除标准版外,还有一个简化版MQTT-SN
,该协议主要针对嵌入式设备,这些设备一般工作于TCP/IP网络,如:ZigBee。
MQTT服务器
实现了MQTT协议的服务器有:
- RabbitMQ
- Apache ActiveMQ
- Apache ActiveMQ Artemis
- Emitter
- Jmqtt
- Vert.x MQTT Broker
- Moquette
- Cassandana
这里有完整的MQTT服务器列表:https://github.com/mqtt/mqtt.github.io/wiki/servers
为了更详细的理解MQTT协议,我们可以看一看Jmqtt的源码,Jmqtt是基于Java和netty实现的,代码量也不太大,不算复杂,容易上手。
MQTT协议规范
HTML:http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html
PDF:http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.pdf
中文版:https://legacy.gitbook.com/book/mcxiaoke/mqtt-cn/details