mqtt.7.xml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <?xml-stylesheet type="text/xsl" href="manpage.xsl"?>
  3. <refentry xml:id="mqtt" xmlns:xlink="http://www.w3.org/1999/xlink">
  4. <refmeta>
  5. <refentrytitle>mqtt</refentrytitle>
  6. <manvolnum>7</manvolnum>
  7. <refmiscinfo class="source">Mosquitto Project</refmiscinfo>
  8. <refmiscinfo class="manual">Conventions and miscellaneous</refmiscinfo>
  9. </refmeta>
  10. <refnamediv>
  11. <refname>mqtt</refname>
  12. <refpurpose>MQ Telemetry Transport</refpurpose>
  13. </refnamediv>
  14. <refsynopsisdiv>
  15. <cmdsynopsis>
  16. <command>MQTT</command>
  17. </cmdsynopsis>
  18. </refsynopsisdiv>
  19. <refsect1>
  20. <title>Description</title>
  21. <para><command>MQTT</command> is a lightweight publish/subscribe
  22. messaging protocol. It is useful for use with low power sensors, but
  23. is applicable to many scenarios.</para> <para>This manual describes
  24. some of the features of MQTT version 3.1.1/3.1, to assist end users in
  25. getting the most out of the protocol. For more complete information on
  26. MQTT, see <uri type="webpage">http://mqtt.org/</uri>.</para>
  27. </refsect1>
  28. <refsect1>
  29. <title>Publish/Subscribe</title>
  30. <para>The MQTT protocol is based on the principle of publishing
  31. messages and subscribing to topics, or "pub/sub". Multiple clients
  32. connect to a broker and subscribe to topics that they are interested
  33. in. Clients also connect to the broker and publish messages to topics.
  34. Many clients may subscribe to the same topics and do with the
  35. information as they please. The broker and MQTT act as a simple, common
  36. interface for everything to connect to. This means that you if you have
  37. clients that dump subscribed messages to a database, to Twitter,
  38. Cosm or even a simple text file, then it becomes very simple to add
  39. new sensors or other data input to a database, Twitter or so on.</para>
  40. </refsect1>
  41. <refsect1>
  42. <title>Topics/Subscriptions</title>
  43. <para>Messages in MQTT are published on topics. There is no need to
  44. configure a topic, publishing on it is enough. Topics are treated as a
  45. hierarchy, using a slash (/) as a separator. This allows sensible
  46. arrangement of common themes to be created, much in the same way as a
  47. filesystem. For example, multiple computers may all publish their
  48. hard drive temperature information on the following topic, with their
  49. own computer and hard drive name being replaced as appropriate:</para>
  50. <itemizedlist>
  51. <listitem><para>sensors/COMPUTER_NAME/temperature/HARDDRIVE_NAME</para></listitem>
  52. </itemizedlist>
  53. <para>Clients can receive messages by creating subscriptions. A
  54. subscription may be to an explicit topic, in which case only messages
  55. to that topic will be received, or it may include wildcards. Two
  56. wildcards are available, <option>+</option> or <option>#</option>.</para>
  57. <para><option>+</option> can be used as a wildcard for a single level
  58. of hierarchy. It could be used with the topic above to get information
  59. on all computers and hard drives as follows:</para>
  60. <itemizedlist>
  61. <listitem><para>sensors/+/temperature/+</para></listitem>
  62. </itemizedlist>
  63. <para>As another example, for a topic of "a/b/c/d", the following
  64. example subscriptions will match:</para>
  65. <itemizedlist mark="circle">
  66. <listitem><para>a/b/c/d</para></listitem>
  67. <listitem><para>+/b/c/d</para></listitem>
  68. <listitem><para>a/+/c/d</para></listitem>
  69. <listitem><para>a/+/+/d</para></listitem>
  70. <listitem><para>+/+/+/+</para></listitem>
  71. </itemizedlist>
  72. <para>The following subscriptions will not match:</para>
  73. <itemizedlist mark="circle">
  74. <listitem><para>a/b/c</para></listitem>
  75. <listitem><para>b/+/c/d</para></listitem>
  76. <listitem><para>+/+/+</para></listitem>
  77. </itemizedlist>
  78. <para><option>#</option> can be used as a wildcard for all remaining levels of
  79. hierarchy. This means that it must be the final character in a
  80. subscription. With a topic of "a/b/c/d", the following example
  81. subscriptions will match:</para>
  82. <itemizedlist mark="circle">
  83. <listitem><para>a/b/c/d</para></listitem>
  84. <listitem><para>#</para></listitem>
  85. <listitem><para>a/#</para></listitem>
  86. <listitem><para>a/b/#</para></listitem>
  87. <listitem><para>a/b/c/#</para></listitem>
  88. <listitem><para>+/b/c/#</para></listitem>
  89. </itemizedlist>
  90. <para>Zero length topic levels are valid, which can lead to some
  91. slightly non-obvious behaviour. For example, a topic of "a//topic"
  92. would correctly match against a subscription of "a/+/topic".
  93. Likewise, zero length topic levels can exist at both the beginning
  94. and the end of a topic string, so "/a/topic" would match against a
  95. subscription of "+/a/topic", "#" or "/#", and a topic "a/topic/"
  96. would match against a subscription of "a/topic/+" or
  97. "a/topic/#".</para>
  98. </refsect1>
  99. <refsect1>
  100. <title>Quality of Service</title>
  101. <para>MQTT defines three levels of Quality of Service (QoS). The QoS
  102. defines how hard the broker/client will try to ensure that a message is
  103. received. Messages may be sent at any QoS level, and clients may
  104. attempt to subscribe to topics at any QoS level. This means that the
  105. client chooses the maximum QoS it will receive. For example, if a
  106. message is published at QoS 2 and a client is subscribed with QoS 0,
  107. the message will be delivered to that client with QoS 0. If a second
  108. client is also subscribed to the same topic, but with QoS 2, then it
  109. will receive the same message but with QoS 2. For a second example, if
  110. a client is subscribed with QoS 2 and a message is published on QoS 0,
  111. the client will receive it on QoS 0.</para>
  112. <para>Higher levels of QoS are more reliable, but involve higher
  113. latency and have higher bandwidth requirements.</para>
  114. <itemizedlist>
  115. <listitem><para>0: The broker/client will deliver the message once, with no confirmation.</para></listitem>
  116. <listitem><para>1: The broker/client will deliver the message at least once, with confirmation required.</para></listitem>
  117. <listitem><para>2: The broker/client will deliver the message exactly once by using a four step handshake.</para></listitem>
  118. </itemizedlist>
  119. </refsect1>
  120. <refsect1>
  121. <title>Retained Messages</title>
  122. <para>All messages may be set to be retained. This means that the
  123. broker will keep the message even after sending it to all current
  124. subscribers. If a new subscription is made that matches the topic of
  125. the retained message, then the message will be sent to the client. This
  126. is useful as a "last known good" mechanism. If a topic is only updated
  127. infrequently, then without a retained message, a newly subscribed
  128. client may have to wait a long time to receive an update. With a
  129. retained message, the client will receive an instant update.</para>
  130. </refsect1>
  131. <refsect1>
  132. <title>Clean session / Durable connections</title>
  133. <para>On connection, a client sets the "clean session" flag, which is
  134. sometimes also known as the "clean start" flag. If clean session is set
  135. to false, then the connection is treated as durable. This means that
  136. when the client disconnects, any subscriptions it has will remain and
  137. any subsequent QoS 1 or 2 messages will be stored until it connects
  138. again in the future. If clean session is true, then all subscriptions
  139. will be removed for the client when it disconnects.</para>
  140. </refsect1>
  141. <refsect1>
  142. <title>Wills</title>
  143. <para>When a client connects to a broker, it may inform the broker that
  144. it has a will. This is a message that it wishes the broker to send when
  145. the client disconnects unexpectedly. The will message has a topic,
  146. QoS and retain status just the same as any other message.</para>
  147. </refsect1>
  148. <refsect1>
  149. <title>See Also</title>
  150. <simplelist type="inline">
  151. <member>
  152. <citerefentry>
  153. <refentrytitle><link xlink:href="mosquitto-8.html">mosquitto</link></refentrytitle>
  154. <manvolnum>8</manvolnum>
  155. </citerefentry>
  156. </member>
  157. <member>
  158. <citerefentry>
  159. <refentrytitle><link xlink:href="mosquitto_pub-1.html">mosquitto_pub</link></refentrytitle>
  160. <manvolnum>1</manvolnum>
  161. </citerefentry>
  162. </member>
  163. <member>
  164. <citerefentry>
  165. <refentrytitle><link xlink:href="mosquitto_sub-1.html">mosquitto_sub</link></refentrytitle>
  166. <manvolnum>1</manvolnum>
  167. </citerefentry>
  168. </member>
  169. </simplelist>
  170. </refsect1>
  171. <refsect1>
  172. <title>Author</title>
  173. <para>Roger Light <email>roger@atchoo.org</email></para>
  174. </refsect1>
  175. </refentry>