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

Source: NATS JetStream

The NATS source subscribes to NATS JetStream subjects and delivers messages into a pg_tide inbox. This enables reverse pipelines where events from NATS-connected services flow reliably into your PostgreSQL database.

Configuration

SELECT tide.relay_set_inbox_v2(
  jsonb_build_object(
    'name', 'events-from-nats',
    'inbox', 'incoming_events',
    'source', 'nats',
    'config', '{
        "url": "tls://nats.example:4222",
        "subject": "events.>",
        "durable_name": "pg-tide-consumer",
        "stream": "EVENTS",
        "ack_wait_secs": 30
    }'::jsonb
  )
);

Configuration Reference

ParameterTypeDefaultDescription
source_typestring—Must be "nats"
urlstring—NATS server URL
subjectstring—Subject filter (supports wildcards: *, >)
durable_namestring—Durable consumer name for offset tracking
streamstringnullJetStream stream name
ack_wait_secsint30Seconds before unacknowledged messages are redelivered
credentials_filestringnullNATS credentials file
batch_sizeint100Messages per inbox insert batch

Delivery Guarantees

The NATS source acknowledges messages only after they are written to the inbox. JetStream's durable consumer retains unacknowledged messages subject to stream retention, and the inbox's deduplication mechanism (using the stable message identity) makes redelivery safe at the database boundary.

Troubleshooting

  • "Consumer not found" — Create the consumer or ensure the stream and subject match
  • "No messages" — Verify the subject filter matches what publishers are sending to
  • High redelivery count — The relay may be slow to acknowledge; increase ack_wait_secs

Further Reading