当前位置:网站首页>One stop solution EMQ for hundreds of millions of communication of Internet of things

One stop solution EMQ for hundreds of millions of communication of Internet of things

2022-06-26 01:48:00 NewBee. Mu

1. MQTT

1.1 MQTT brief introduction

1.1.1 What is? MQTT

MQTT(Message Queuing Telemetry Transport, Message queuing telemetry transmission protocol ), It's based on publishing / subscribe (publish/subscribe) Mode " Lightweight " Communication protocol , The agreement is built on TCP/IP Agreement on , from IBM stay 1999 Released in .MQTT The biggest advantage is , With very little code and limited bandwidth , Provide real-time and reliable message services for connecting remote devices . As a low cost 、 Low bandwidth instant messaging protocol , Make it in the Internet of things 、 Small equipment 、 Mobile applications are widely used .

 Insert picture description here
A use MQTT Protocol applications or devices , It always establishes a network connection to the server . The client can :

  • (1) Publish information that other clients may subscribe to ;
  • (2) Subscribe to messages published by other clients ;
  • (3) Unsubscribe or delete messages from the application ;
  • (4) Disconnect from the server .

MQTT The server is called " The message broker "(Broker), It can be an application or a device . It is between the publisher and the subscriber , It can :

  • (1) Accept network connections from customers ;
  • (2) Accept application information released by customers ;
  • (3) Handle subscription and unsubscribe requests from clients ;
  • (4) Forward application messages to subscribers .

1.1.2 Design principles

Because the environment of the Internet of things is very special , therefore MQTT Follow the following design principles :

  • (1) Streamlining , Do not add dispensable functions ;

  • (2) Release / subscribe (Pub/Sub) Pattern , It's convenient for messages to pass between sensors , decoupling Client/Server Pattern , The advantage is that you don't have to know each other's existence in advance (ip/port), You don't have to run at the same time ;

  • (3) Allow users to create themes dynamically ( There is no need to create a theme in advance ), Zero operation and maintenance cost ;

  • (4) Minimize the amount of transmission to improve transmission efficiency ;

  • (5) Put low bandwidth 、 High latency 、 Unstable networks and other factors are taken into account ;

  • (6) Support continuous session maintenance and control ( heartbeat );

  • (7) Understanding client computing power can be very low ;

  • (8) Provide quality of service ( quality of service level:QoS) management

  • (9) The type and format of data transmission are not required , Stay flexible ( It refers to the application layer business data ).

1.1.3 Application field

MQTT The protocol is widely used in the Internet of things 、 Mobile Internet 、 Smart hardware 、 Car networking 、 Electricity, energy and other fields .

  • The Internet of things M2M signal communication , Internet of things big data collection
  • Android Message push ,WEB Message push
  • Mobile instant messaging , for example Facebook Messenger
  • Smart hardware 、 Smart home 、 Intelligent electrical apparatus
  • Vehicle networking communication , Electric vehicle station pile collection
  • Smart city 、 telemedicine 、 distance learning
  • Electric power 、 Oil, energy and other industry markets

1.2 MQTT Protocol related concepts

1.2.1 MQTT Protocol implementation

Realization MQTT The protocol needs the communication between client and server , In the course of communication ,MQTT There are three identities in the agreement : Publisher (Publisher)、 agent (Broker)( The server )、 subscriber (Subscriber). among , Both the publisher and the subscriber of the message are clients , A message broker is a server , The publisher can be a subscriber at the same time .

MQTT The messages transmitted are divided into : The theme (Topic) And the load (payload) Two parts :

  • (1)Topic, It can be understood as the type of message , Subscribers subscribe to (Subscribe) after , You will receive the message content of the topic (payload);
  • (2)payload, It can be understood as the content of the message , It refers to the specific content that the subscriber wants to use .

1.2.2 MQTT The method in the agreement

MQTT Some methods are defined in the protocol ( It's also called action ), Represents the operation on the determined resource . This resource can represent pre-existing data or dynamically generated data , It depends on the implementation of the server . Generally speaking , A resource is a file or output on a server . The main methods are :

  • (1)CONNECT: Client connects to server
  • (2)CONNACK: Connect to confirm
  • (3)PUBLISH: Release the news
  • (4)PUBACK: Release confirmation
  • (5)PUBREC: The published message has been received
  • (6)PUBREL: The published message has been released
  • (7)PUBCOMP: Release complete
  • (8)SUBSCRIBE: Subscription request
  • (9)SUBACK: Subscription confirmation
  • (10)UNSUBSCRIBE: Unsubscribe
  • (11)UNSUBACK: Unsubscribe confirmation
  • (12)PINGREQ: Client sends heartbeat
  • (13)PINGRESP: Server heartbeat response
  • (14)DISCONNECT: disconnect
  • (15)AUTH: authentication

1.3 Message quality of service QoS

MQTT The protocol specifies the quality of message service (Quality of Service), It ensures the reliability of message delivery in different network environments ,QoS The design of MQTT The point of the agreement . As a protocol designed for the Internet of things scenario ,MQTT It's not just PC, It's more extensive narrow bandwidth networks and low-power devices , If we can solve the problem of transmission quality in the protocol layer , It will provide great convenience for the development of Internet of things applications .

1.3.1 Message quality of service QoS Three grades

MQTT Designed 3 individual QoS Grade .

  • QoS 0: The message can be delivered at most once , If the client is not available at that time , The message is lost .
  • QoS 1: Messaging at least 1 Time .
  • QoS 2: Messages are delivered only once .

QoS0:“ One more time ”, Message publishing is completely dependent on the underlying TCP/IP The Internet . There will be a loss or repetition of messages . This level can be used for , Environmental sensor data , It doesn't matter if you lose a read , Because there will be a second delivery soon . This way is mainly common APP Push of , If your smart device is not connected to the Internet when the message is pushed , I didn't receive the push , Again networking will not receive .

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-EgEIe7u6-1656158766013)(images/4.png)]

QoS1:“ At least once ”, Make sure that the message arrives , But repetition can happen .

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-xs92blpA-1656158766014)(images/5.png)]

QoS2:“ For once ”, Make sure the message arrives once . In some strict billing systems , You can use this level . In the billing system , Duplicate or missing messages can lead to incorrect results . This highest quality messaging service can also be used for instant messaging APP Push of , Make sure that users receive and will receive only once .

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-JOKZMyPW-1656158766014)(images/6.png)]

1.3.2 Publish and subscribe QoS

MQTT In publish and subscribe operations QoS Represents different meanings , At the time of release QoS Indicates the message used when sending to the server QoS, At the time of subscription QoS Indicates the maximum number of messages that the server can use when forwarding messages to itself QoS.

  • When the client A Release QoS Larger than the client B The subscription QoS when , Server to client B Used when forwarding messages QoS For the client B The subscription QoS.
  • When the client A Release QoS Less than client B The subscription QoS when , Server to client B Used when forwarding messages QoS For the client A Release QoS.

Messages received by the client under different circumstances QoS Please refer to the table below :

The one who publishes the news QoS Subject subscription QoS To receive a message QoS
000
010
020
100
111
121
200
211
222

1.4 Topic Wildcard matching rules

Level separator :/

/ Used to split each layer of the topic tree , And provide a hierarchical structure for the theme space . When two wildcards appear in a topic , The use of topic level separators is important .

 Example :
love/you/with/all/my/heart

Multi level wildcards :#

Multi level wildcards can represent greater than or equal to 0 The level of . therefore ,love/# It can also be matched to a separate love, here # representative 0 layer .

The multi-level wildcard must be the last character of the topic tree . for instance ,love/# It works , however love/#/with It's invalid .

love/you/#	 Match the following ( Including but not limited to )

love/you
love/you/with
love/you/with/all
love/you/with/all/my/heart
love/you/with/all/my/hearts

Single layer wildcard :+

Only one level of the subject is matched .

1. love/you/+  : matching love/you/with and love/you/and, But it doesn't match love/you/with/all/my/heart.
2.  Single level wildcards only match 1 layer ,love/+ Mismatch love.
3.  Single level wildcards can be used at any level of the topic tree , Concatenated multi-level wildcard . It must be used in the topic level separator / To the right of , Unless it specifies itself . therefore ,+ and love/+ It's all valid , however love+ Invalid . Single level wildcards can be used at the end of the topic tree , It can also be used in the middle . for instance ,love/+ and love/+/with It's all effective .

matters needing attention

1. The topic hierarchy separator is used to introduce hierarchies into the topic . Multi level wildcards and single level wildcards can be used , But they can't be used as a publisher's message .
2.Topic Try to see the meaning of the name , Conform to specifications , Subject names are case sensitive . for instance ,love and LOVE There are two different themes .
3. With / The beginning will produce a different theme . for instance ,/love And love Different ./love matching "+/+" and /+, But don't match +
4. Do not include... In any topic null(Unicode \x0000) character .
5. In the topic tree , The length is limited to 64k But there is no limit to the number of levels  .
6. There can be any number of root nodes ; in other words , There can be any number of topic trees .

2. EMQX

2.1 EMQ X brief introduction

EMQ X Is the most popular in the open source community MQTT Message server .

EMQ Official website :https://www.emqx.cn/

EMQ X The company mainly provides three versions : Open source Edition 、 Enterprise Edition 、 Platform version You can view each product in the product navigation on the homepage of the official website ; This is mainly reflected in the number of supported connections 、 Differences in product functions and business services .

Why choose EMQ X ?
From support MQTT5.0、 stability 、 Extensibility 、 Cluster capability and so on ,EMQX Should be the best .

EMQ X It's open source, millions of distributed MQTT Message server (MQTT Messaging Broker), Used to support various access standards MQTT Agreed devices , Realize the message transmission from the device side to the server side , And device control message forwarding from server to device . So as to realize the data acquisition of Internet of things devices , And the operation and control of the equipment .

With others MQTT Server comparison ,EMQ X It mainly has the following characteristics :

  • after 100+ Iteration of version ,EMQ X At present, it is the most popular in the open source community MQTT Message middleware , In a variety of customers' strict production environment has withstood severe tests ;

  • EMQ X Support rich Internet of things protocols , Include MQTT、MQTT-SN、CoAP、 LwM2M、LoRaWAN and WebSocket etc. ;

  • Optimized architecture design , Support large-scale device connection . The enterprise stand-alone can support millions of MQTT Connect ; Clusters can support tens of millions of levels of MQTT Connect ;

  • Easy to install and use ;

  • Flexible scalability , Support some customized scenarios of enterprises ;

  • Local technical support in China , Through WeChat 、QQ And other online channels to quickly respond to customer needs ;

  • be based on Apache 2.0 Agreement license , Fully open source .EMQ X The code is placed in Github in , Users can view all source code .

  • EMQ X 3.0 Support MQTT 5.0 agreement , Is the first open source community to support 5.0 Protocol specification message server , And fully compatible MQTT V3.1 and V3.1.1 agreement . except MQTT Beyond the agreement ,EMQ X It also supports some other Internet of things protocols

  • A single machine supports millions of connections , The cluster supports tens of millions of connections ; Millisecond message forwarding .EMQ X A variety of technologies are applied to realize the above functions ,

    • utilize Erlang/OTP Soft real-time of the platform 、 High concurrency and fault tolerance ( The proven language of Telecommunications )
    • All asynchronous architecture
    • Connect 、 conversation 、 route 、 Hierarchical design of cluster
    • Separation of message plane and control plane, etc
  • Extension modules and plug-ins ,EMQ X Provides a flexible extension mechanism , Private protocols can be implemented 、 Authentication 、 Data persistence 、 Extension of bridge forwarding and management console

  • The bridge :EMQ X It can connect with other message systems , such as EMQ X Enterprise The version can support forwarding messages to Kafka、RabbitMQ Or something EMQ Nodes etc.

  • Share subscription : Shared subscriptions support distribution among multiple subscribers through load balancing MQTT news . For example, for data acquisition scenarios such as the Internet of things , There will be more devices sending data , By sharing subscriptions, multiple subscribers can be set at the subscriber end to achieve workload balance among these subscribers

原网站

版权声明
本文为[NewBee. Mu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206252358200193.html