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