1MOSQUITTO_RR(1) Commands MOSQUITTO_RR(1)
2
3
4
6 mosquitto_rr - an MQTT version 5/3.1.1 client for request/response
7 messaging
8
10 mosquitto_rr -e response-topic
11 {[-h hostname] [--unix socket path] [-p port-number] [-u username] [-P password] -t message-topic...
12 | -L URL [-t message-topic...] } {-f file | -m message |
13 -n | -s} [-A bind-address] [-c] [-d]
14 [-D command identifier value] [-i client-id]
15 [-I client-id-prefix] [-k keepalive-time] [-N] [--nodelay]
16 [--pretty] [-q message-QoS] [-R] [-S] [-v]
17 [-V protocol-version] [-W message-processing-timeout]
18 [-x session-expiry-interval] [--proxy socks-url] [--quiet]
19 [--will-topic topic [--will-payload payload] [--will-qos qos] [--will-retain]]
20 [[{--cafile file | --capath dir} [--cert file] [--key file] [--ciphers ciphers] [--tls-version version] [--tls-alpn protocol] [--tls-engine engine] [--keyform {pem | engine}] [--tls-engine-kpass-sha1 kpass-sha1] [--tls-use-os-certs] [--insecure]]
21 |
22 [--psk hex-key --psk-identity identity [--ciphers ciphers] [--tls-version version]]]
23
24 mosquitto_rr [--help]
25
27 mosquitto_rr is an MQTT version 5/3.1.1 client that can be used to
28 publish a request message and wait for a response. When using MQTT v5,
29 which is the default, mosquitto_rr will use the Request-Response
30 feature.
31
32 The important options are -t, -e, and one of -f, -m, -n, and -s.
33
34 Example: mosquitto_rr -t request-topic -e response-topic -m message
35
37 mosquitto_rr supports TLS encrypted connections. It is strongly
38 recommended that you use an encrypted connection for anything more than
39 the most basic setup.
40
41 To enable TLS connections when using x509 certificates, one of either
42 --cafile or --capath must be provided as an option.
43
44 To enable TLS connections when using TLS-PSK, you must use the --psk
45 and the --psk-identity options.
46
48 The options below may be given on the command line, but may also be
49 placed in a config file located at $XDG_CONFIG_HOME/mosquitto_rr or
50 $HOME/.config/mosquitto_rr with one pair of -option value per line. The
51 values in the config file will be used as defaults and can be
52 overridden by using the command line. The exceptions to this is -t,
53 which if given in the config file will not be overridden. Note also
54 that currently some options cannot be negated, e.g. -S. Config file
55 lines that have a # as the first character are treated as comments and
56 not processed any further.
57
58 -A
59 Bind the outgoing connection to a local ip address/hostname. Use
60 this argument if you need to restrict network communication to a
61 particular interface.
62
63 -c, --disable-clean-session
64 Disable 'clean session' / enable persistent client mode. When this
65 argument is used, the broker will be instructed not to clean
66 existing sessions for the same client id when the client connects,
67 and sessions will never expire when the client disconnects. MQTT v5
68 clients can change their session expiry interval with the -x
69 argument.
70
71 When a session is persisted on the broker, the subscriptions for
72 the client will be maintained after it disconnects, along with
73 subsequent QoS 1 and QoS 2 messages that arrive. When the client
74 reconnects and does not clean the session, it will receive all of
75 the queued messages.
76
77 If using this option, the client id must be set manually with --id
78
79 --cafile
80 Define the path to a file containing PEM encoded CA certificates
81 that are trusted. Used to enable SSL communication.
82
83 See also --capath
84
85 --capath
86 Define the path to a directory containing PEM encoded CA
87 certificates that are trusted. Used to enable SSL communication.
88
89 For --capath to work correctly, the certificate files must have
90 ".crt" as the file ending and you must run "openssl rehash <path to
91 capath>" each time you add/remove a certificate.
92
93 See also --cafile
94
95 --cert
96 Define the path to a file containing a PEM encoded certificate for
97 this client, if required by the server.
98
99 See also --key.
100
101 --ciphers
102 An openssl compatible list of TLS ciphers to support in the client.
103 See ciphers(1) for more information.
104
105 -d, --debug
106 Enable debug messages.
107
108 -D, --property
109 Use an MQTT v5 property with this publish. If you use this option,
110 the client will be set to be an MQTT v5 client. This option has two
111 forms:
112
113 -D command identifier value
114
115 -D command identifier name value
116
117 command is the MQTT command/packet identifier and can be one of
118 CONNECT, PUBACK, PUBREC, PUBCOMP, SUBSCRIBE, UNSUBSCRIBE,
119 DISCONNECT, AUTH, or WILL. The properties available for each
120 command are listed in the Properties section.
121
122 identifier is the name of the property to add. This is as described
123 in the specification, but with '-' as a word separator. For
124 example: payload-format-indicator. More details are in the
125 Properties section.
126
127 value is the value of the property to add, with a data type that is
128 property specific.
129
130 name is only used for the user-property property as the first of
131 the two strings in the string pair. In that case, value is the
132 second of the strings in the pair.
133
134 -e
135 Response topic. The client will subscribe to this topic to wait for
136 a response.
137
138 -f, --file
139 Send the contents of a file as the request message.
140
141 -F
142 Specify output printing format. This option allows you to choose
143 what information from each message is printed to the screen. See
144 the Output Format section below for full details.
145
146 This option overrides the -v option, but does not override the -N
147 option.
148
149 --help
150 Display usage information.
151
152 -h, --host
153 Specify the host to connect to. Defaults to localhost.
154
155 -i, --id
156 The id to use for this client. If not given, a client id will be
157 generated depending on the MQTT version being used. For
158 v3.1.1/v3.1, the client generates a client id in the format
159 mosq-XXXXXXXXXXXXXXXXXX, where the X are replaced with random
160 alphanumeric characters. For v5.0, the client sends a zero length
161 client id, and the server will generate a client id for the client.
162
163 This option cannot be used at the same time as the --id-prefix
164 argument.
165
166 -I, --id-prefix
167 Provide a prefix that the client id will be built from by appending
168 the process id of the client. This is useful where the broker is
169 using the clientid_prefixes option. Cannot be used at the same time
170 as the --id argument.
171
172 --insecure
173 When using certificate based encryption, this option disables
174 verification of the server hostname in the server certificate. This
175 can be useful when testing initial server configurations but makes
176 it possible for a malicious third party to impersonate your server
177 through DNS spoofing, for example. Use this option in testing only.
178 If you need to resort to using this option in a production
179 environment, your setup is at fault and there is no point using
180 encryption.
181
182 -k, --keepalive
183 The number of seconds between sending PING commands to the broker
184 for the purposes of informing it we are still connected and
185 functioning. Defaults to 60 seconds.
186
187 --key
188 Define the path to a file containing a PEM encoded private key for
189 this client, if required by the server.
190
191 See also --cert.
192
193 --keyform
194 Specifies the type of private key in use when making TLS
195 connections.. This can be "pem" or "engine". This parameter is
196 useful when a TPM module is being used and the private key has been
197 created with it. Defaults to "pem", which means normal private key
198 files are used.
199
200 See also --tls-engine.
201
202 -L, --url
203 Specify specify user, password, hostname, port and topic at once as
204 a URL. The URL must be in the form:
205 mqtt(s)://[username[:password]@]host[:port]/topic
206
207 If the scheme is mqtt:// then the port defaults to 1883. If the
208 scheme is mqtts:// then the port defaults to 8883.
209
210 -m, --message
211 Send a single request message from the command line.
212
213 -N
214 Do not append an end of line character to the payload when
215 printing. This allows streaming of payload data from multiple
216 messages directly to another application unmodified. Only really
217 makes sense when not using -v.
218
219 -n, --null-message
220 Send a null (zero length) request message.
221
222 --nodelay
223 Disable Nagle's algorithm for the socket. This means that latency
224 of sent messages is reduced, which is particularly noticable for
225 small, reasonably infrequent messages. Using this option may result
226 in more packets being sent than would normally be necessary.
227
228 -p, --port
229 Connect to the port specified. If not given, the default of 1883
230 for plain MQTT or 8883 for MQTT over TLS will be used.
231
232 -P, --pw
233 Provide a password to be used for authenticating with the broker.
234 Using this argument without also specifying a username is invalid
235 when using MQTT v3.1 or v3.1.1. See also the --username option.
236
237 --pretty
238 When using the JSON output format %j or %J, the default is to print
239 in an unformatted fashion. Specifying --pretty prints messages in a
240 prettier, more human readable format.
241
242 --proxy
243 Specify a SOCKS5 proxy to connect through. "None" and "username"
244 authentication types are supported. The socks-url must be of the
245 form socks5h://[username[:password]@]host[:port]. The protocol
246 prefix socks5h means that hostnames are resolved by the proxy. The
247 symbols %25, %3A and %40 are URL decoded into %, : and @
248 respectively, if present in the username or password.
249
250 If username is not given, then no authentication is attempted. If
251 the port is not given, then the default of 1080 is used.
252
253 More SOCKS versions may be available in the future, depending on
254 demand, and will use different protocol prefixes as described in
255 curl(1).
256
257 --psk
258 Provide the hexadecimal (no leading 0x) pre-shared-key matching the
259 one used on the broker to use TLS-PSK encryption support.
260 --psk-identity must also be provided to enable TLS-PSK.
261
262 --psk-identity
263 The client identity to use with TLS-PSK support. This may be used
264 instead of a username if the broker is configured to do so.
265
266 -q, --qos
267 Specify the quality of service desired for the incoming messages,
268 from 0, 1 and 2. Defaults to 0. See mqtt(7) for more information on
269 QoS.
270
271 The QoS is identical for all topics subscribed to in a single
272 instance of mosquitto_rr.
273
274 --quiet
275 If this argument is given, no runtime errors will be printed. This
276 excludes any error messages given in case of invalid user input
277 (e.g. using --port without a port).
278
279 -R
280 If this argument is given, messages that are received that have the
281 retain bit set will not be printed. Messages with retain set are
282 "stale", in that it is not known when they were originally
283 published. When subscribing to a wildcard topic there may be a
284 large number of retained messages. This argument suppresses their
285 display.
286
287 -S
288 Use SRV lookups to determine which host to connect to. Performs
289 lookups to _mqtt._tcp.<host> when used in conjunction with -h,
290 otherwise uses _mqtt._tcp.<local dns domain>.
291
292 -s, --stdin-file
293 Send a request message read from stdin, sending the entire content
294 as a single message.
295
296 -t, --topic
297 The MQTT topic where the request message will be sent.
298
299 --tls-alpn
300 Provide a protocol to use when connecting to a broker that has
301 multiple protocols available on a single port, e.g. MQTT and
302 WebSockets.
303
304 --tls-engine
305 A valid openssl engine id. These can be listed with openssl engine
306 command.
307
308 See also --keyform.
309
310 --tls-engine-kpass-sha1
311 SHA1 of the private key password when using an TLS engine. Some TLS
312 engines such as the TPM engine may require the use of a password in
313 order to be accessed. This option allows a hex encoded SHA1 hash of
314 the password to the engine directly, instead of the user being
315 prompted for the password.
316
317 See also --tls-engine.
318
319 --tls-use-os-certs
320 If used, this will load and trust the OS provided CA certificates.
321 This can be used in conjunction with --cafile and --capath and can
322 be used on its own to enable TLS mode. This will be set by default
323 if -L mqtts://... is used, or if port is 8883 and no other
324 certificate options are used.
325
326 --tls-version
327 Choose which TLS protocol version to use when communicating with
328 the broker. Valid options are tlsv1.3, tlsv1.2 and tlsv1.1. The
329 default value is tlsv1.2. Must match the protocol version used by
330 the broker.
331
332 -u, --username
333 Provide a username to be used for authenticating with the broker.
334 See also the --pw argument.
335
336 --unix
337 Connect to a broker through a local unix domain socket instead of a
338 TCP socket. This is a replacement for -h and -L. For example:
339 mosquitto_pub --unix /tmp/mosquitto.sock ...
340
341 See the socket_domain option in mosquitto.conf[1m(5) to configure
342 Mosquitto to listen on a unix socket.
343
344 -v, --verbose
345 Print received messages verbosely. With this argument, messages
346 will be printed as "topic payload". When this argument is not
347 given, the messages are printed as "payload".
348
349 -V, --protocol-version
350 Specify which version of the MQTT protocol should be used when
351 connecting to the rmeote broker. Can be 5, 311, 31, or the more
352 verbose mqttv5, mqttv311, or mqttv31. Defaults to 5.
353
354 --will-payload
355 Specify a message that will be stored by the broker and sent out if
356 this client disconnects unexpectedly. This must be used in
357 conjunction with --will-topic.
358
359 --will-qos
360 The QoS to use for the Will. Defaults to 0. This must be used in
361 conjunction with --will-topic.
362
363 --will-retain
364 If given, if the client disconnects unexpectedly the message sent
365 out will be treated as a retained message. This must be used in
366 conjunction with --will-topic.
367
368 --will-topic
369 The topic on which to send a Will, in the event that the client
370 disconnects unexpectedly.
371
372 -x
373 Set the session-expiry-interval property on the CONNECT packet.
374 Applies to MQTT v5 clients only. Set to 0-4294967294 to specify the
375 session will expire in that many seconds after the client
376 disconnects, or use -1, 4294967295, or ∞ for a session that does
377 not expire. Defaults to -1 if -c is also given, or 0 if -c not
378 given.
379
380 If the session is set to never expire, either with -x or -c, then a
381 client id must be provided.
382
384 There are three ways of formatting the output from mosquitto_rr. In all
385 cases a new-line character is appended for each message received unless
386 the -N argument is passed to mosquitto_rr.
387
388 Payload-only is the default output format and will print the payload
389 exactly as it is received.
390
391 Verbose mode is activated with -v and prints the message topic and the
392 payload, separated by a space.
393
394 The final option is formatted output, which allows the user to define a
395 custom output format. The behaviour is controlled with the -F
396 format-string option. The format string is a free text string where
397 interpreted sequences are replaced by different parameters. The
398 available interpreted sequences are described below.
399
400 Three characters are used to start an interpreted sequence: %, @ and \.
401 Sequences starting with % are either parameters related to the MQTT
402 message being printed, or are helper sequences to avoid the need to
403 type long date format strings for example. Sequences starting with @
404 are passed to the strftime(3) function (with the @ replaced with a % -
405 note that only the character immediately after the @ is passed to
406 strftime). This allows the construction of a wide variety of time based
407 outputs. The output options for strftime vary from platform to
408 platform, so please check what is available for your platform.
409 mosquitto_rr does provide one extension to strftime which is @N, which
410 can be used to obtain the number of nanoseconds passed in the current
411 second. The resolution of this option varies depending on the platform.
412 The final sequence character is \, which is used to input some
413 characters that would otherwise be difficult to enter.
414
415 MQTT related parameters
416 • %% a literal %.
417
418 • %A the MQTT v5 topic-alias property, if present.
419
420 • %C the MQTT v5 content-type property, if present.
421
422 • %D the MQTT v5 correlation-data property, if present. Note that
423 this property is specified as binary data, so may produce
424 non-printable characters.
425
426 • %E the MQTT v5 message-expiry-interval property, if present.
427
428 • %F the MQTT v5 payload-format-indicator property, if present.
429
430 • %l the length of the payload in bytes.
431
432 • %m the message id (only relevant for messages with QoS>0).
433
434 • %P the MQTT v5 user-property property, if present. This will be
435 printed in the form key:value. It is possible for any number of
436 user properties to be attached to a message, and to have duplicate
437 keys.
438
439 • %p the payload raw bytes (may produce non-printable characters
440 depending on the payload).
441
442 • %q the message QoS.
443
444 • %R the MQTT v5 response-topic property, if present.
445
446 • %r the retained flag for the message.
447
448 • %S the MQTT v5 subscription-identifier property, if present.
449
450 • %t the message topic.
451
452 • %x the payload with each byte as a hexadecimal number (lower case).
453
454 • %X the payload with each byte as a hexadecimal number (upper case).
455
456 Helpers
457 • %I ISO-8601 format date and time, e.g. 2016-08-10T09:47:38+0100
458
459 • %j JSON output of message parameters and timestamp, with a quoted
460 and escaped payload. For example
461 {"tst":"2020-05-06T22:12:00.000000+0100","topic":"greeting","qos":0,"retain":0,"payload":"hello
462 world"}
463
464 • %J JSON output of message parameters and timestamp, with a
465 non-quoted and non-escaped payload - this means the payload must
466 itself be valid JSON. For example:
467 {"tst":"2020-05-06T22:12:00.000000+0100","topic":"foo","qos":0,"retain":0,"payload":{"temperature":27.0,"humidity":57}}.
468
469 If the payload is not valid JSON, then the error message "Error:
470 Message payload is not valid JSON on topic <topic>" will be printed
471 to stderr.
472
473 • %I ISO-8601 format date and time, e.g. 2016-08-10T09:47:38+0100
474
475 • %U Unix timestamp with nanoseconds, e.g. 1470818943.786368637
476
477 Time related parameters
478 • @@ a literal @.
479
480 • @X pass the character represented by X to the strftime function as
481 %X. The options supported are platform dependent.
482
483 • @N the number of nanoseconds that have passed in the current
484 second, with varying timing resolution depending on platform.
485
486 Escape characters
487 • \\ a literal \.
488
489 • \0 a null character. Can be used to separate different parameters
490 that may contain spaces (e.g. topic, payload) so that processing
491 with tools such as xargs(1) is easier.
492
493 • \a alert/bell.
494
495 • \e the escape sequence, which can be used with ANSI colour codes to
496 provide coloured output for example.
497
498 • \n end of line.
499
500 • \r carriage return.
501
502 • \t horizontal tab.
503
504 • \v vertical tab.
505
507 mosquitto_rr can register a message with the broker that will be sent
508 out if it disconnects unexpectedly. See mqtt(7) for more information.
509
510 The minimum requirement for this is to use --will-topic to specify
511 which topic the will should be sent out on. This will result in a
512 non-retained, zero length message with QoS 0.
513
514 Use the --will-retain, --will-payload and --will-qos arguments to
515 modify the other will parameters.
516
518 The -D / --property option allows adding properties to different stages
519 of the mosquitto_rr run. The properties supported for each command are
520 as follows:
521
522 Connect
523 • authentication-data (binary data - note treated as a string in
524 mosquitto_rr)
525
526 • authentication-method (UTF-8 string pair)
527
528 • maximum-packet-size (32-bit unsigned integer)
529
530 • receive-maximum (16-bit unsigned integer)
531
532 • request-problem-information (8-bit unsigned integer)
533
534 • request-response-information (8-bit unsigned integer)
535
536 • session-expiry-interval (32-bit unsigned integer, note use -x
537 instead)
538
539 • topic-alias-maximum (16-bit unsigned integer)
540
541 • user-property (UTF-8 string pair)
542
543 Publish
544 • content-type (UTF-8 string)
545
546 • correlation-data (binary data - note treated as a string in
547 mosquitto_rr)
548
549 • message-expiry-interval (32-bit unsigned integer)
550
551 • payload-format-indicator (8-bit unsigned integer)
552
553 • response-topic (UTF-8 string)
554
555 • topic-alias (16-bit unsigned integer)
556
557 • user-property (UTF-8 string pair)
558
559 Subscribe
560 • user-property (UTF-8 string pair)
561
562 Unsubscribe
563 • user-property (UTF-8 string pair)
564
565 Disconnect
566 • session-expiry-interval (32-bit unsigned integer)
567
568 • user-property (UTF-8 string pair)
569
570 Will properties
571 • content-type (UTF-8 string)
572
573 • correlation-data (binary data - note treated as a string in
574 mosquitto_pub)
575
576 • message-expiry-interval (32-bit unsigned integer)
577
578 • payload-format-indicator (8-bit unsigned integer)
579
580 • response-topic (UTF-8 string)
581
582 • user-property (UTF-8 string pair)
583
584 • will-delay-interval (32-bit unsigned integer)
585
587 0
588 Success
589
590 27
591 Timed out waiting for message
592
593 Other non-zero value
594 Unspecified failure
595
597 $XDG_CONFIG_HOME/mosquitto_rr, $HOME/.config/mosquitto_rr
598 Configuration file for default options.
599
601 mosquitto bug information can be found at
602 https://github.com/eclipse/mosquitto/issues
603
605 mqtt(7), mosquitto_pub(1), mosquitto_sub(1), mosquitto(8),
606 libmosquitto(3), mosquitto-tls(7)
607
609 Roger Light <roger@atchoo.org>
610
611
612
613Mosquitto Project 04/03/2021 MOSQUITTO_RR(1)