NATS
Publish, request-reply and subscribe on NATS, and use JetStream streams with acknowledged publish and durable consumers. Typical uses: light messaging between services, IoT events.
nats pingnats publishnats publishnats publish_batchnats publish_batchnats requestnats requestnats consumenats consumenats stream_createnats stream_createnats js_publishnats js_publishnats streamsnats stream_infonats js_consumenats js_consumenats js_acknats js_nacknats stream_drop
nats ping <config>
Description
Connect, authenticate and make a PING. Returns {ok, latency_ms, server_version, jetstream, max_payload, tls}; a failure is an error
Connect, authenticate and make a PING. Returns {ok, latency_ms, server_version, jetstream, max_payload, tls}; a failure is an error
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
admin
nats ping "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}"
mentdb
{"ok": true, "latency_ms": 4, "server_version": "2.15.3", "jetstream": true, "max_payload": 1048576, "tls": false}
a bad password (fixed result: a real local nats-server 2.15.3 with JetStream)
admin
nats ping "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_wrong_password\"}"
mentdb
ERROR: Sorry, an error appears (NATS: authorization violation: check the username, the password or the token).
nats publish <config> <subject> <body>
Description
Publish a text and make a round trip, so a refusal of the server is seen. Returns {subject, bytes}
Publish a text and make a round trip, so a refusal of the server is seen. Returns {subject, bytes}
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject: tokens separated by dots (orders.eu.new), without spaces or control characters, 1024 bytes at most; * (one token) and > (the last tokens) only to subscribe - String - required
body: The text, sent in UTF-8 - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject: tokens separated by dots (orders.eu.new), without spaces or control characters, 1024 bytes at most; * (one token) and > (the last tokens) only to subscribe - String - required
body: The text, sent in UTF-8 - String - required
admin
nats publish "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "orders.eu" "order 1"
mentdb
{"subject": "orders.eu", "bytes": 7}
nats publish <config> <subject> <body> <json_params>
Description
Publish with parameters: headers (a JSON object of texts), reply_to (a subject for the answer), encoding (utf-8, or base64: the body is decoded and sent as bytes)
Publish with parameters: headers (a JSON object of texts), reply_to (a subject for the answer), encoding (utf-8, or base64: the body is decoded and sent as bytes)
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject: tokens separated by dots (orders.eu.new), without spaces or control characters, 1024 bytes at most; * (one token) and > (the last tokens) only to subscribe - String - required
body: The text or the base64 - String - required
json_params: The parameters - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject: tokens separated by dots (orders.eu.new), without spaces or control characters, 1024 bytes at most; * (one token) and > (the last tokens) only to subscribe - String - required
body: The text or the base64 - String - required
json_params: The parameters - String - required
admin
nats publish "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "orders.raw" "//4Aaw==" "{\"encoding\": \"base64\", \"headers\": {\"source\": \"erp\"}}"
mentdb
{"subject": "orders.raw", "bytes": 4}
nats publish_batch <config> <json_rows>
Description
Publish a list of rows {subject, body, headers} on one connection, with a round trip every 1000 messages and at the end. Returns {sent, failed, not_attempted, errors}: errors has at most 100 entries {row, error}; an invalid row, or one larger than max_payload with its headers, does not stop the list; a connection error stops it: the rows since the last round trip are counted as failed (some may have been taken), the next ones as not_attempted
Publish a list of rows {subject, body, headers} on one connection, with a round trip every 1000 messages and at the end. Returns {sent, failed, not_attempted, errors}: errors has at most 100 entries {row, error}; an invalid row, or one larger than max_payload with its headers, does not stop the list; a connection error stops it: the rows since the last round trip are counted as failed (some may have been taken), the next ones as not_attempted
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
json_rows: The messages as a JSON array of objects (100000 at most). A body that is not a text is sent as JSON - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
json_rows: The messages as a JSON array of objects (100000 at most). A body that is not a text is sent as JSON - String - required
admin
nats publish_batch "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "[{\"subject\": \"orders.eu\", \"body\": \"order 2\"}, {\"subject\": \"orders..eu\", \"body\": \"x\"}, {\"subject\": \"orders.us\", \"body\": {\"id\": 3}}]"
mentdb
{"sent": 2, "failed": 1, "not_attempted": 0, "errors": [{"row": 1, "error": "the subject 'orders..eu' has an empty token (two dots, or a dot at the start or at the end)"}]}
nats publish_batch <config> <json_rows> <json_params>
Description
Publish a list with parameters: subject_field (subject), body_field (body), headers (for every row), encoding (utf-8)
Publish a list with parameters: subject_field (subject), body_field (body), headers (for every row), encoding (utf-8)
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
json_rows: The messages as a JSON array of objects (100000 at most). A body that is not a text is sent as JSON - String - required
json_params: The parameters - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
json_rows: The messages as a JSON array of objects (100000 at most). A body that is not a text is sent as JSON - String - required
json_params: The parameters - String - required
admin
nats publish_batch "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "[{\"s\": \"orders.eu\", \"v\": \"order 4\"}]" "{\"subject_field\": \"s\", \"body_field\": \"v\", \"headers\": {\"batch\": \"b1\"}}"
mentdb
{"sent": 1, "failed": 0, "not_attempted": 0, "errors": []}
nats request <config> <subject> <body>
Description
Send a request and wait 5 seconds for one reply, on a new inbox. Returns {body, encoding}, with headers when present. No subscriber gives the error no responder at once; no reply in time is an error
Send a request and wait 5 seconds for one reply, on a new inbox. Returns {body, encoding}, with headers when present. No subscriber gives the error no responder at once; no reply in time is an error
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject: tokens separated by dots (orders.eu.new), without spaces or control characters, 1024 bytes at most; * (one token) and > (the last tokens) only to subscribe - String - required
body: The text - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject: tokens separated by dots (orders.eu.new), without spaces or control characters, 1024 bytes at most; * (one token) and > (the last tokens) only to subscribe - String - required
body: The text - String - required
admin
nats request "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "svc.echo" "hello"
mentdb
{"body": "echo: hello", "encoding": "utf-8"}
no service on this subject (fixed result: a real local nats-server 2.15.3 with JetStream)
admin
nats request "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "svc.none" "hello"
mentdb
ERROR: Sorry, an error appears (NATS: no responder on the subject 'svc.none').
nats request <config> <subject> <body> <json_params>
Description
Request with parameters: wait_ms (5000, up to 600000), headers, encoding
Request with parameters: wait_ms (5000, up to 600000), headers, encoding
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject: tokens separated by dots (orders.eu.new), without spaces or control characters, 1024 bytes at most; * (one token) and > (the last tokens) only to subscribe - String - required
body: The text or the base64 - String - required
json_params: The parameters - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject: tokens separated by dots (orders.eu.new), without spaces or control characters, 1024 bytes at most; * (one token) and > (the last tokens) only to subscribe - String - required
body: The text or the base64 - String - required
json_params: The parameters - String - required
admin
nats request "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "svc.echo" "status" "{\"wait_ms\": 2000, \"headers\": {\"lang\": \"fr\"}}"
mentdb
{"body": "echo: status", "encoding": "utf-8"}
nats consume <config> <subject>
Description
Subscribe and read during 5 seconds, at most 100 messages and 16 MB. Returns rows {subject, body, encoding}, with reply_to and headers when present. Only the messages published during the call are seen
Subscribe and read during 5 seconds, at most 100 messages and 16 MB. Returns rows {subject, body, encoding}, with reply_to and headers when present. Only the messages published during the call are seen
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject, with the wildcards * and > if needed - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject, with the wildcards * and > if needed - String - required
admin
nats consume "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "sensors.*"
mentdb
[{"subject": "sensors.room1", "body": "21.5", "encoding": "utf-8"}, {"subject": "sensors.room2", "body": "19.0", "encoding": "utf-8"}, {"subject": "sensors.room1", "body": "21.7", "encoding": "utf-8"}]
nats consume <config> <subject> <json_params>
Description
Read with parameters: max_messages (100, up to 100000), wait_ms (5000, up to 600000: the whole reading), queue_group (the subscribers of a group share the messages), max_bytes (16 MB, up to 256 MB)
Read with parameters: max_messages (100, up to 100000), wait_ms (5000, up to 600000: the whole reading), queue_group (the subscribers of a group share the messages), max_bytes (16 MB, up to 256 MB)
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject - String - required
json_params: The parameters - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject - String - required
json_params: The parameters - String - required
admin
nats consume "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "sensors.>" "{\"max_messages\": 2, \"wait_ms\": 3000, \"queue_group\": \"workers\"}"
mentdb
[{"subject": "sensors.room1", "body": "21.5", "encoding": "utf-8"}, {"subject": "sensors.room2", "body": "19.0", "encoding": "utf-8"}]
nats stream_create <config> <stream> <subjects>
Description
Create a JetStream stream on subjects (a subject or a JSON array of subjects): file storage, limits retention. Creating it again with the same configuration is accepted. Returns {stream, subjects, storage, retention, messages, bytes, first_seq, last_seq, consumers}
Create a JetStream stream on subjects (a subject or a JSON array of subjects): file storage, limits retention. Creating it again with the same configuration is accepted. Returns {stream, subjects, storage, retention, messages, bytes, first_seq, last_seq, consumers}
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
stream: The name of the stream: 1 to 255 letters, digits, - or _ - String - required
subjects: A subject or a JSON array of subjects, with wildcards - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
stream: The name of the stream: 1 to 255 letters, digits, - or _ - String - required
subjects: A subject or a JSON array of subjects, with wildcards - String - required
admin
nats stream_create "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "ORDERS" "orders.>"
mentdb
{"stream": "ORDERS", "subjects": ["orders.>"], "storage": "file", "retention": "limits", "messages": 0, "bytes": 0, "first_seq": 0, "last_seq": 0, "consumers": 0}
nats stream_create <config> <stream> <subjects> <json_params>
Description
Create a stream with parameters: storage (file or memory), retention (limits, interest or workqueue), max_msgs, max_bytes, max_age_ms, max_msg_size (-1: no limit), replicas (1 to 5), discard (old or new), duplicate_window_ms (the window of msg_id, 2 minutes), description
Create a stream with parameters: storage (file or memory), retention (limits, interest or workqueue), max_msgs, max_bytes, max_age_ms, max_msg_size (-1: no limit), replicas (1 to 5), discard (old or new), duplicate_window_ms (the window of msg_id, 2 minutes), description
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
stream: The name of the stream: 1 to 255 letters, digits, - or _ - String - required
subjects: A subject or a JSON array - String - required
json_params: The parameters - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
stream: The name of the stream: 1 to 255 letters, digits, - or _ - String - required
subjects: A subject or a JSON array - String - required
json_params: The parameters - String - required
admin
nats stream_create "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "JOBS" "[\"jobs.*\"]" "{\"storage\": \"memory\", \"retention\": \"workqueue\", \"max_age_ms\": 86400000}"
mentdb
{"stream": "JOBS", "subjects": ["jobs.*"], "storage": "memory", "retention": "workqueue", "messages": 0, "bytes": 0, "first_seq": 0, "last_seq": 0, "consumers": 0}
another configuration under an existing name (fixed result: a real local nats-server 2.15.3 with JetStream)
admin
nats stream_create "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "JOBS" "jobs.*"
mentdb
ERROR: Sorry, an error appears (NATS JetStream error 10058: stream name already in use with a different configuration).
nats js_publish <config> <subject> <body>
Description
Publish to a stream and wait for its acknowledgement. Returns {stream, seq, duplicate}. A subject without a stream is an error (no responder); no acknowledgement in time is an error, the message may or may not be stored
Publish to a stream and wait for its acknowledgement. Returns {stream, seq, duplicate}. A subject without a stream is an error (no responder); no acknowledgement in time is an error, the message may or may not be stored
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject: tokens separated by dots (orders.eu.new), without spaces or control characters, 1024 bytes at most; * (one token) and > (the last tokens) only to subscribe - String - required
body: The text - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject: tokens separated by dots (orders.eu.new), without spaces or control characters, 1024 bytes at most; * (one token) and > (the last tokens) only to subscribe - String - required
body: The text - String - required
admin
nats js_publish "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "orders.eu" "order 10"
mentdb
{"stream": "ORDERS", "seq": 1, "duplicate": false}
no stream on this subject (fixed result: a real local nats-server 2.15.3 with JetStream)
admin
nats js_publish "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "invoices.eu" "invoice 1"
mentdb
ERROR: Sorry, an error appears (NATS: no stream takes the subject 'invoices.eu' (no responder)).
nats js_publish <config> <subject> <body> <json_params>
Description
Publish to a stream with parameters: msg_id (the Nats-Msg-Id header: the same id within the duplicate window is stored once, duplicate true), expected_stream (refused if another stream takes the subject), headers, encoding
Publish to a stream with parameters: msg_id (the Nats-Msg-Id header: the same id within the duplicate window is stored once, duplicate true), expected_stream (refused if another stream takes the subject), headers, encoding
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject: tokens separated by dots (orders.eu.new), without spaces or control characters, 1024 bytes at most; * (one token) and > (the last tokens) only to subscribe - String - required
body: The text or the base64 - String - required
json_params: The parameters - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
subject: The subject: tokens separated by dots (orders.eu.new), without spaces or control characters, 1024 bytes at most; * (one token) and > (the last tokens) only to subscribe - String - required
body: The text or the base64 - String - required
json_params: The parameters - String - required
admin
nats js_publish "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "orders.us" "order 11" "{\"msg_id\": \"o-11\", \"headers\": {\"source\": \"web\"}}"
mentdb
{"stream": "ORDERS", "seq": 2, "duplicate": false}
the same id again (fixed result: a real local nats-server 2.15.3 with JetStream)
admin
nats js_publish "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "orders.us" "order 11" "{\"msg_id\": \"o-11\"}"
mentdb
{"stream": "ORDERS", "seq": 2, "duplicate": true}
a job (fixed result: a real local nats-server 2.15.3 with JetStream)
admin
nats js_publish "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "jobs.mail" "send report" "{\"expected_stream\": \"JOBS\"}"
mentdb
{"stream": "JOBS", "seq": 1, "duplicate": false}
nats streams <config>
Description
List the streams. Returns rows as nats stream_create
List the streams. Returns rows as nats stream_create
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
admin
nats streams "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}"
mentdb
[{"stream": "JOBS", "subjects": ["jobs.*"], "storage": "memory", "retention": "workqueue", "messages": 1, "bytes": 76, "first_seq": 1, "last_seq": 1, "consumers": 0}, {"stream": "ORDERS", "subjects": ["orders.>"], "storage": "file", "retention": "limits", "messages": 2, "bytes": 142, "first_seq": 1, "last_seq": 2, "consumers": 0}]
nats stream_info <config> <stream>
Description
The state of a stream, as nats stream_create with exists true. An unknown stream gives {stream, exists: false}, not an error
The state of a stream, as nats stream_create with exists true. An unknown stream gives {stream, exists: false}, not an error
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
stream: The name of the stream: 1 to 255 letters, digits, - or _ - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
stream: The name of the stream: 1 to 255 letters, digits, - or _ - String - required
admin
nats stream_info "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "ORDERS"
mentdb
{"stream": "ORDERS", "exists": true, "subjects": ["orders.>"], "storage": "file", "retention": "limits", "messages": 2, "bytes": 142, "first_seq": 1, "last_seq": 2, "consumers": 0}
no such stream (fixed result: a real local nats-server 2.15.3 with JetStream)
admin
nats stream_info "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "NOPE"
mentdb
{"stream": "NOPE", "exists": false}
nats js_consume <config> <stream> <consumer>
Description
Read at most 100 messages and 16 MB with a durable pull consumer (created when missing: explicit ack, from the first message), waiting up to 5 seconds on an empty stream, and acknowledge them. Returns rows {subject, body, encoding, headers, stream_seq, delivered, pending, timestamp_ns, ack_id}: delivered counts the deliveries of the message, pending the messages left for the consumer
Read at most 100 messages and 16 MB with a durable pull consumer (created when missing: explicit ack, from the first message), waiting up to 5 seconds on an empty stream, and acknowledge them. Returns rows {subject, body, encoding, headers, stream_seq, delivered, pending, timestamp_ns, ack_id}: delivered counts the deliveries of the message, pending the messages left for the consumer
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
stream: The name of the stream: 1 to 255 letters, digits, - or _ - String - required
consumer: The name of the durable consumer: 1 to 255 letters, digits, - or _ - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
stream: The name of the stream: 1 to 255 letters, digits, - or _ - String - required
consumer: The name of the durable consumer: 1 to 255 letters, digits, - or _ - String - required
admin
nats js_consume "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "ORDERS" "billing"
mentdb
[{"subject": "orders.eu", "body": "order 10", "encoding": "utf-8", "stream_seq": 1, "delivered": 1, "pending": 1, "timestamp_ns": 1794932723959410000, "ack_id": "$JS.ACK.ORDERS.billing.1.1.1.1794932723959410000.1"}, {"subject": "orders.us", "body": "order 11", "encoding": "utf-8", "headers": {"source": "web", "Nats-Msg-Id": "o-11"}, "stream_seq": 2, "delivered": 1, "pending": 0, "timestamp_ns": 1794932724377910000, "ack_id": "$JS.ACK.ORDERS.billing.1.2.2.1794932724377910000.0"}]
nats js_consume <config> <stream> <consumer> <json_params>
Description
Read with parameters: max_messages (100, up to 100000), wait_ms (5000, up to 600000; 0: no wait), ack (true; false: the messages stay pending, see nats js_ack), max_bytes (16 MB, up to 256 MB), create (true; false: an unknown consumer is an error), and for a consumer created here: filter_subject, deliver_policy (all, new, last or last_per_subject)
Read with parameters: max_messages (100, up to 100000), wait_ms (5000, up to 600000; 0: no wait), ack (true; false: the messages stay pending, see nats js_ack), max_bytes (16 MB, up to 256 MB), create (true; false: an unknown consumer is an error), and for a consumer created here: filter_subject, deliver_policy (all, new, last or last_per_subject)
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
stream: The name of the stream: 1 to 255 letters, digits, - or _ - String - required
consumer: The name of the durable consumer - String - required
json_params: The parameters - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
stream: The name of the stream: 1 to 255 letters, digits, - or _ - String - required
consumer: The name of the durable consumer - String - required
json_params: The parameters - String - required
admin
nats js_consume "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "ORDERS" "us-audit" "{\"ack\": false, \"filter_subject\": \"orders.us\", \"wait_ms\": 1000}"
mentdb
[{"subject": "orders.us", "body": "order 11", "encoding": "utf-8", "headers": {"source": "web", "Nats-Msg-Id": "o-11"}, "stream_seq": 2, "delivered": 1, "pending": 0, "timestamp_ns": 1794932724377910000, "ack_id": "$JS.ACK.ORDERS.us-audit.1.2.1.1794932724377910000.0"}]
a job (fixed result: a real local nats-server 2.15.3 with JetStream)
admin
nats js_consume "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "JOBS" "mailer" "{\"ack\": false, \"max_messages\": 1, \"wait_ms\": 1000}"
mentdb
[{"subject": "jobs.mail", "body": "send report", "encoding": "utf-8", "headers": {"Nats-Expected-Stream": "JOBS"}, "stream_seq": 1, "delivered": 1, "pending": 0, "timestamp_ns": 1794932724810587000, "ack_id": "$JS.ACK.JOBS.mailer.1.1.1.1794932724810587000.0"}]
nats js_ack <config> <ack_ids>
Description
Acknowledge messages read with ack false: their ack_id, a JSON array of them, or the rows of nats js_consume. Returns {acked}. NATS does not answer an ack: an ack_id that is too old or wrong is ignored by the server
Acknowledge messages read with ack false: their ack_id, a JSON array of them, or the rows of nats js_consume. Returns {acked}. NATS does not answer an ack: an ack_id that is too old or wrong is ignored by the server
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
ack_ids: One ack_id, a JSON array, or rows with the field ack_id - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
ack_ids: One ack_id, a JSON array, or rows with the field ack_id - String - required
admin
nats js_ack "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "$JS.ACK.ORDERS.us-audit.1.2.1.1794932724377910000.0"
mentdb
{"acked": 1}
nats js_nack <config> <ack_ids>
Description
Give back messages read with ack false (-NAK): they are delivered again at once. Returns {nacked}
Give back messages read with ack false (-NAK): they are delivered again at once. Returns {nacked}
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
ack_ids: One ack_id, a JSON array, or rows with the field ack_id - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
ack_ids: One ack_id, a JSON array, or rows with the field ack_id - String - required
admin
nats js_nack "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "$JS.ACK.JOBS.mailer.1.1.1.1794932724810587000.0"
mentdb
{"nacked": 1}
nats stream_drop <config> <stream>
Description
Delete a stream and its messages. Returns {stream, dropped}
Delete a stream and its messages. Returns {stream, dropped}
Parameters
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
stream: The name of the stream: 1 to 255 letters, digits, - or _ - String - required
config: The NATS configuration as JSON: url (nats://host:4222 or tls://host:4222, without credentials), or host, port (4222) and tls (false), then username and password (the name of a secret: secret set) or token (the name of a secret: secret set), timeout_ms (10000, from 100 to 600000, for the connection and for each answer), allow_plain (false: credentials without TLS are refused unless the host is localhost or 127.x.x.x; no DNS request decides this). With TLS the certificate and the host name are checked: ca_file (a PEM or DER certificate file of a private CA), or trust_all (false; true accepts any certificate, for a test only). A server that requires TLS is refused without tls true - String - required
stream: The name of the stream: 1 to 255 letters, digits, - or _ - String - required
admin
nats stream_drop "{\"url\": \"nats://127.0.0.1:4222\", \"username\": \"mq\", \"password\": \"nats_password\"}" "JOBS"
mentdb
{"stream": "JOBS", "dropped": true}
