mqtt.7 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. '\" t
  2. .\" Title: mqtt
  3. .\" Author: [see the "Author" section]
  4. .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
  5. .\" Date: 10/27/2021
  6. .\" Manual: Conventions and miscellaneous
  7. .\" Source: Mosquitto Project
  8. .\" Language: English
  9. .\"
  10. .TH "MQTT" "7" "10/27/2021" "Mosquitto Project" "Conventions and miscellaneous"
  11. .\" -----------------------------------------------------------------
  12. .\" * Define some portability stuff
  13. .\" -----------------------------------------------------------------
  14. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. .\" http://bugs.debian.org/507673
  16. .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  17. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. mqtt \- MQ Telemetry Transport
  32. .SH "SYNOPSIS"
  33. .HP \w'\fBMQTT\fR\ 'u
  34. \fBMQTT\fR
  35. .SH "DESCRIPTION"
  36. .PP
  37. \fBMQTT\fR
  38. is a lightweight publish/subscribe messaging protocol\&. It is useful for use with low power sensors, but is applicable to many scenarios\&.
  39. .PP
  40. This manual describes some of the features of MQTT version 3\&.1\&.1/3\&.1, to assist end users in getting the most out of the protocol\&. For more complete information on MQTT, see
  41. http://mqtt\&.org/\&.
  42. .SH "PUBLISH/SUBSCRIBE"
  43. .PP
  44. The MQTT protocol is based on the principle of publishing messages and subscribing to topics, or "pub/sub"\&. Multiple clients connect to a broker and subscribe to topics that they are interested in\&. Clients also connect to the broker and publish messages to topics\&. Many clients may subscribe to the same topics and do with the information as they please\&. The broker and MQTT act as a simple, common interface for everything to connect to\&. This means that you if you have clients that dump subscribed messages to a database, to Twitter, Cosm or even a simple text file, then it becomes very simple to add new sensors or other data input to a database, Twitter or so on\&.
  45. .SH "TOPICS/SUBSCRIPTIONS"
  46. .PP
  47. Messages in MQTT are published on topics\&. There is no need to configure a topic, publishing on it is enough\&. Topics are treated as a hierarchy, using a slash (/) as a separator\&. This allows sensible arrangement of common themes to be created, much in the same way as a filesystem\&. For example, multiple computers may all publish their hard drive temperature information on the following topic, with their own computer and hard drive name being replaced as appropriate:
  48. .sp
  49. .RS 4
  50. .ie n \{\
  51. \h'-04'\(bu\h'+03'\c
  52. .\}
  53. .el \{\
  54. .sp -1
  55. .IP \(bu 2.3
  56. .\}
  57. sensors/COMPUTER_NAME/temperature/HARDDRIVE_NAME
  58. .RE
  59. .PP
  60. Clients can receive messages by creating subscriptions\&. A subscription may be to an explicit topic, in which case only messages to that topic will be received, or it may include wildcards\&. Two wildcards are available,
  61. \fB+\fR
  62. or
  63. \fB#\fR\&.
  64. .PP
  65. \fB+\fR
  66. can be used as a wildcard for a single level of hierarchy\&. It could be used with the topic above to get information on all computers and hard drives as follows:
  67. .sp
  68. .RS 4
  69. .ie n \{\
  70. \h'-04'\(bu\h'+03'\c
  71. .\}
  72. .el \{\
  73. .sp -1
  74. .IP \(bu 2.3
  75. .\}
  76. sensors/+/temperature/+
  77. .RE
  78. .PP
  79. As another example, for a topic of "a/b/c/d", the following example subscriptions will match:
  80. .sp
  81. .RS 4
  82. .ie n \{\
  83. \h'-04'\(bu\h'+03'\c
  84. .\}
  85. .el \{\
  86. .sp -1
  87. .IP \(bu 2.3
  88. .\}
  89. a/b/c/d
  90. .RE
  91. .sp
  92. .RS 4
  93. .ie n \{\
  94. \h'-04'\(bu\h'+03'\c
  95. .\}
  96. .el \{\
  97. .sp -1
  98. .IP \(bu 2.3
  99. .\}
  100. +/b/c/d
  101. .RE
  102. .sp
  103. .RS 4
  104. .ie n \{\
  105. \h'-04'\(bu\h'+03'\c
  106. .\}
  107. .el \{\
  108. .sp -1
  109. .IP \(bu 2.3
  110. .\}
  111. a/+/c/d
  112. .RE
  113. .sp
  114. .RS 4
  115. .ie n \{\
  116. \h'-04'\(bu\h'+03'\c
  117. .\}
  118. .el \{\
  119. .sp -1
  120. .IP \(bu 2.3
  121. .\}
  122. a/+/+/d
  123. .RE
  124. .sp
  125. .RS 4
  126. .ie n \{\
  127. \h'-04'\(bu\h'+03'\c
  128. .\}
  129. .el \{\
  130. .sp -1
  131. .IP \(bu 2.3
  132. .\}
  133. +/+/+/+
  134. .RE
  135. .PP
  136. The following subscriptions will not match:
  137. .sp
  138. .RS 4
  139. .ie n \{\
  140. \h'-04'\(bu\h'+03'\c
  141. .\}
  142. .el \{\
  143. .sp -1
  144. .IP \(bu 2.3
  145. .\}
  146. a/b/c
  147. .RE
  148. .sp
  149. .RS 4
  150. .ie n \{\
  151. \h'-04'\(bu\h'+03'\c
  152. .\}
  153. .el \{\
  154. .sp -1
  155. .IP \(bu 2.3
  156. .\}
  157. b/+/c/d
  158. .RE
  159. .sp
  160. .RS 4
  161. .ie n \{\
  162. \h'-04'\(bu\h'+03'\c
  163. .\}
  164. .el \{\
  165. .sp -1
  166. .IP \(bu 2.3
  167. .\}
  168. +/+/+
  169. .RE
  170. .PP
  171. \fB#\fR
  172. can be used as a wildcard for all remaining levels of hierarchy\&. This means that it must be the final character in a subscription\&. With a topic of "a/b/c/d", the following example subscriptions will match:
  173. .sp
  174. .RS 4
  175. .ie n \{\
  176. \h'-04'\(bu\h'+03'\c
  177. .\}
  178. .el \{\
  179. .sp -1
  180. .IP \(bu 2.3
  181. .\}
  182. a/b/c/d
  183. .RE
  184. .sp
  185. .RS 4
  186. .ie n \{\
  187. \h'-04'\(bu\h'+03'\c
  188. .\}
  189. .el \{\
  190. .sp -1
  191. .IP \(bu 2.3
  192. .\}
  193. #
  194. .RE
  195. .sp
  196. .RS 4
  197. .ie n \{\
  198. \h'-04'\(bu\h'+03'\c
  199. .\}
  200. .el \{\
  201. .sp -1
  202. .IP \(bu 2.3
  203. .\}
  204. a/#
  205. .RE
  206. .sp
  207. .RS 4
  208. .ie n \{\
  209. \h'-04'\(bu\h'+03'\c
  210. .\}
  211. .el \{\
  212. .sp -1
  213. .IP \(bu 2.3
  214. .\}
  215. a/b/#
  216. .RE
  217. .sp
  218. .RS 4
  219. .ie n \{\
  220. \h'-04'\(bu\h'+03'\c
  221. .\}
  222. .el \{\
  223. .sp -1
  224. .IP \(bu 2.3
  225. .\}
  226. a/b/c/#
  227. .RE
  228. .sp
  229. .RS 4
  230. .ie n \{\
  231. \h'-04'\(bu\h'+03'\c
  232. .\}
  233. .el \{\
  234. .sp -1
  235. .IP \(bu 2.3
  236. .\}
  237. +/b/c/#
  238. .RE
  239. .PP
  240. Zero length topic levels are valid, which can lead to some slightly non\-obvious behaviour\&. For example, a topic of "a//topic" would correctly match against a subscription of "a/+/topic"\&. Likewise, zero length topic levels can exist at both the beginning and the end of a topic string, so "/a/topic" would match against a subscription of "+/a/topic", "#" or "/#", and a topic "a/topic/" would match against a subscription of "a/topic/+" or "a/topic/#"\&.
  241. .SH "QUALITY OF SERVICE"
  242. .PP
  243. MQTT defines three levels of Quality of Service (QoS)\&. The QoS defines how hard the broker/client will try to ensure that a message is received\&. Messages may be sent at any QoS level, and clients may attempt to subscribe to topics at any QoS level\&. This means that the client chooses the maximum QoS it will receive\&. For example, if a message is published at QoS 2 and a client is subscribed with QoS 0, the message will be delivered to that client with QoS 0\&. If a second client is also subscribed to the same topic, but with QoS 2, then it will receive the same message but with QoS 2\&. For a second example, if a client is subscribed with QoS 2 and a message is published on QoS 0, the client will receive it on QoS 0\&.
  244. .PP
  245. Higher levels of QoS are more reliable, but involve higher latency and have higher bandwidth requirements\&.
  246. .sp
  247. .RS 4
  248. .ie n \{\
  249. \h'-04'\(bu\h'+03'\c
  250. .\}
  251. .el \{\
  252. .sp -1
  253. .IP \(bu 2.3
  254. .\}
  255. 0: The broker/client will deliver the message once, with no confirmation\&.
  256. .RE
  257. .sp
  258. .RS 4
  259. .ie n \{\
  260. \h'-04'\(bu\h'+03'\c
  261. .\}
  262. .el \{\
  263. .sp -1
  264. .IP \(bu 2.3
  265. .\}
  266. 1: The broker/client will deliver the message at least once, with confirmation required\&.
  267. .RE
  268. .sp
  269. .RS 4
  270. .ie n \{\
  271. \h'-04'\(bu\h'+03'\c
  272. .\}
  273. .el \{\
  274. .sp -1
  275. .IP \(bu 2.3
  276. .\}
  277. 2: The broker/client will deliver the message exactly once by using a four step handshake\&.
  278. .RE
  279. .SH "RETAINED MESSAGES"
  280. .PP
  281. All messages may be set to be retained\&. This means that the broker will keep the message even after sending it to all current subscribers\&. If a new subscription is made that matches the topic of the retained message, then the message will be sent to the client\&. This is useful as a "last known good" mechanism\&. If a topic is only updated infrequently, then without a retained message, a newly subscribed client may have to wait a long time to receive an update\&. With a retained message, the client will receive an instant update\&.
  282. .SH "CLEAN SESSION / DURABLE CONNECTIONS"
  283. .PP
  284. On connection, a client sets the "clean session" flag, which is sometimes also known as the "clean start" flag\&. If clean session is set to false, then the connection is treated as durable\&. This means that when the client disconnects, any subscriptions it has will remain and any subsequent QoS 1 or 2 messages will be stored until it connects again in the future\&. If clean session is true, then all subscriptions will be removed for the client when it disconnects\&.
  285. .SH "WILLS"
  286. .PP
  287. When a client connects to a broker, it may inform the broker that it has a will\&. This is a message that it wishes the broker to send when the client disconnects unexpectedly\&. The will message has a topic, QoS and retain status just the same as any other message\&.
  288. .SH "SEE ALSO"
  289. \fBmosquitto\fR(8), \fBmosquitto_pub\fR(1), \fBmosquitto_sub\fR(1)
  290. .SH "AUTHOR"
  291. .PP
  292. Roger Light
  293. <roger@atchoo\&.org>