Open source Mqtt Agent: Mosquitto

Source: Internet
Author: User
Tags stdin valid port number

Original link: http://blog.chinaunix.net/uid-25885064-id-3538994.html
MQTT (MQ Telemetry Transport), Message Queuing Telemetry transport Protocol, lightweight Publish/Subscribe protocol, for low bandwidth, unreliable, or intermittent communication in some demanding environments. It is worth mentioning that MQTT offers three different quality messaging services:
"At most once", message publishing relies entirely on the underlying TCP/IP network. Message loss or repetition occurs. This level can be used when the environment sensor data, loss of a read record does not matter, because there will be a second time to send.
"At least once" to ensure that the message arrives, but the message duplication may occur.
"Only once" to make sure the message arrives once. This level can be used for situations where, in a billing system, duplicate or missing messages can result in incorrect results.
The following is a more detailed introduction link.
MQ Telemetry Transport (MQTT) V3.1 Protocol specification:
Http://www.ibm.com/developerworks/cn/webservices/ws-mqtt/index.html

Mosquitto is an open source broker and supports MQTTv3.1 to support client-side validation. The Mosquitto includes the server and the client.

The Mosquitto_pub client can publish a message to the specified topic:
Usage:
Mosquitto_pub [-d] [-h hostname] [-I client_id] [-I client ID prefix] [-p port number] [-Q message QoS] [–quiet] [-r] {-F File | -L | -M message | -N | -S} [-u username [-p password]] [–will-topic topic [–will-payload Payload] [–will-qos QoS] [–will-retain]]-t message-t OPIc
Options:
-d,–debug
Turn on debug options
-f,–file
Send the content of a file as the content of the message. Test, support TXT file, not support Doc and other forms of file.
-h,–host
Description of the domain name you are connected to, default is localhost
-i,–id
The ID number of the client and, if not specified, the default is Mosquitto_pub_ plus the client's process ID, which cannot be used with –id_prefix.
-i,–id-prefix
Specifies the prefix of the client ID, the ID of the client that is connected to the client's process ID, and cannot be used concurrently with – ID.
-l,–stdin-line
Read input from the total segment sends a message, a behavior message, and a blank line is not sent.
-m,–message
Send a message from the command line, followed by-M with the message content sent.
-n,–null-message
Send an empty message.
-p,–port
The port number of the connection, which is 1883 by default.
-p,–pw
Specifies that the password is used for proxy authentication and must have a valid user name when using this option.
-q,–qos
Specifies the quality of service for the message, which can be 0,1,2, which is 0 by default.
–quiet
If this option is specified, no errors are printed, of course, which excludes the error messages that are caused by invalid user input.
-r,–retain
If this option is specified, the message is persisted as the last message received. The next subscriber will be able to receive at least the message.
-s,–stdin-file
Receives the transmitted message content from the standard input, all inputs are sent as a message.
-t,–topic
Specifies which topic the message is published to.
-u,–username
Specifies that the user name is used for proxy authentication.
–will-payload
If this option is specified, if the client unexpectedly and the proxy server disconnects, the message is left on the service side and sent out, which must also specify the subject with –will-topic.
–will-qos
Specifies the quality of Will's service, which is 0 by default. Must be used in conjunction with option –will-topic.
–will-retain
If this option is specified, messages that have been sent will be treated as retained messages in the event that the client disconnects unexpectedly. Must be used in conjunction with the option –will-topic.
–will-topic
Specifies the subject to which the would message is sent when the client disconnects unexpectedly.

Sub_client a client to subscribe to one or more topic messages:
Usage:
Mosquitto_sub [-c] [-d] [-h hostname] [-I client_id] [-I client ID prefix] [-K keepalive Time] [-p port number] [-Q MESSAG E QoS] [–quiet] [-v] [-u username [-ppassword]] [–will-topic topic [–will-payload Payload] [–will-qos QoS] [–will-retai N]]-T message topic ...
Command:
Mosquitto_sub subscribe to a topic, print when a message is received
Options:
-c,–disable-clean-session
The ' Clean Session ' option is prohibited, that is, if the client disconnects, the subscription remains to receive subsequent QoS messages of 1 and 2, and when the client is reconnected, it receives a message that is queued. It is recommended that the Client ID option be set to – ID when this option is used
If using this option, it was recommended that the client ID is set manually with–id
-d,–debug
Turn on debug options
-h,–host
Description of the domain name you are connected to, default is localhost
-i,–id
The ID number of the client and, if not specified, the default is Mosquitto_pub_ plus the client's process ID, which cannot be used with –id_prefix.
-i,–id-prefix
Specifies the prefix of the client ID, the ID of the client that is connected to the client's process ID, and cannot be used concurrently with – ID.
-k,–keepalive
Send a ping to the agent (the purpose is to tell the agent that the client connection is kept and working) at a time that is 60s by default
-p,–port
Indicates the port to which the client is connected, default is 1883
-p,–pw
Specifies that the password is used for proxy authentication and must have a valid user name when using this option.
-q,–qos
Specifies the quality of service for the message, which can be 0,1,2, which is 0 by default.
–quiet
If this option is specified, no errors are printed, of course, which excludes the error messages that are caused by invalid user input.
-t,–topic
Specifies the message subject of the subscription, allowing simultaneous subscription to multiple topics
-u,–username
Specifies that the user name is used for proxy authentication.
-v,–verbose
Print the received message in a verbose manner. If you specify this option, the subject name-"Subject message Content"-is printed before the message, otherwise, only the message content is printed
–will-payload
If this option is specified, if the client unexpectedly and the proxy server disconnects, the message is left on the service side and sent out, which must also specify the subject with –will-topic.
–will-qos
Specifies the quality of Will's service, which is 0 by default. Must be used in conjunction with option –will-topic.
–will-retain
If this option is specified, messages that have been sent will be treated as retained messages in the event that the client disconnects unexpectedly. Must be used in conjunction with the option –will-topic.
–will-topic
Specifies the subject to which the would message is sent when the client disconnects unexpectedly.

Type of message

1. Connection request (Connect)
When a TCP/IP socket connection from the client to the server is established, a connection flow must be used to create a protocol-level session.

2. Connection request Confirmation (Connectack)
The connection request acknowledgement message (Connectack) is the server sent to the client to confirm the client's connection request

3. Release message (PUBLISH)
The client publishes the message to the server side, which is used to provide subscribers with different needs. Each published message has a theme, which is a hierarchical namespace that defines the classification of message sources and allows subscribers to subscribe to the topics they need. Subscribers can register their own required message categories.

4. Release confirmation message (puback)
The release confirmation message (Puback) is a response to a release message with a service quality level of 1. It can be the server's message confirmation to the client that posted the message, or the message subscriber's response to the server that posted the message.

5. Release confirmation message (PUBREC)
The PUBREC message is a response to a release message with a service quality level of 2. This is the second message of a protocol flow with a service quality level of 2. Pubrec is the server-side response to the client that posted the message, or the message subscriber's response to the server that posted the message.

6. Release confirmation message (Pubrel)
Pubrel is the acknowledgement of the message publisher of the PUBREC message from the server, or the server's acknowledgement of the PUBREC message from the subscriber of the message. It is the third message of a protocol flow with a service quality level of 2.

7. Determine release completion (PUBCOMP)
The PUBCOMP message is the server's response to the message publisher's Pubrel message, or the message subscriber's Pubrel message to the server. It is the fourth and last message of a protocol flow with a service quality level of 2.

8. Subscribe to named topics (SUBSCRIBE)
The subscription message (SUBSCRIBE) allows a client to register one or more subject names of interest on the server. Messages issued to these topics are delivered to clients as release messages from the server side. The subscription message also describes the quality of service level of the posting message that the Subscriber wants to receive.

Subscription Message Confirmation (SUBACK)
When the server receives a subscription message from the client, the acknowledgement message of the subscription message is sent to the client. One such acknowledgment message contains a list of service quality levels that are granted. The order in which the quality of service is granted and the subject name in the corresponding subscription message match.

Unsubscribe from named topics (unsubscribe)
The unsubscribe message is sent from the client to the server side to unsubscribe from the named topic.

Unsubscribe Confirmation (Unsuback)
The unsubscribe confirmation message is sent from the server to the client to confirm the unsubscribe request message sent by the client.

Ping request (PINGREQ)
The ping request message is sent from the connected client to the server side to ask if the server side is still present.

Ping Answer (PINGRESP)
A ping response message is a client that is sent from the server side to the ping request, confirming the client's ping request.

Disconnect notification (DISCONNECT)
The Disconnect notification message is sent from the client to the server side to indicate the TCP/IP connection that will close it, allowing for a complete disconnection rather than just a downline. If the client has contacted the clean session flag set, all previous information about client maintenance will be discarded. After a server receives a disconnected message, it cannot rely on the client to close the TCP/IP connection.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.