Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

NATS

Publishes to or consumes from NATS subjects. Uses JetStream by default (durable, acked); set no_jetstream=true for fire-and-forget Core NATS.

URL format

nats://host[:port]?subject=<subject>[&stream=<name>]

For a multi-server cluster, pass a comma-separated list via the ?url= escape hatch: nats://_/?url=nats://n1:4222,nats://n2:4222&subject=orders. Consumers require stream (the JetStream stream name), even with no_jetstream=true (validated but unused there). If the bridge auto-creates a stream it is scoped to {stream}.>, so prefix your subject accordingly.

Examples

Load a JSONL file into a JetStream subject, one-shot:

mq-bridge-app copy --drain \
  --from file:///data/orders.jsonl?format=json \
  --to 'nats://localhost:4222?subject=orders&stream=ORDERS'

Consume a durable JetStream stream into Postgres, continuous:

mq-bridge-app copy \
  --from 'nats://localhost:4222?subject=orders&stream=ORDERS' \
  --to 'postgres://user:pass@localhost/app?table=orders&auto_create_table=true'

Core NATS request/reply (no JetStream), continuous:

mq-bridge-app copy \
  --from http://0.0.0.0:8080/rpc \
  --to 'nats://localhost:4222?subject=rpc.echo&no_jetstream=true&request_reply=true'

Key options

OptionPurpose
subjectSubject to publish to or subscribe to.
streamJetStream stream name. Required for consumers.
no_jetstreamUse Core NATS (fire-and-forget) instead of JetStream.
deliver_policyConsumer-only: all (default), last, new, last_per_subject.
subscriber_modeConsumer-only: ephemeral subscriber instead of a durable consumer.
request_reply + request_timeout_msPublisher-only request/reply pattern.
deduplicatePublisher-only (JetStream): send Nats-Msg-Id so JetStream dedupes redeliveries.
username / password / tokenAuthentication.
tlsTLS configuration (object; set with a JSON literal ?tls={...}).

Full field list: reference/nats.md.