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(
    'events-from-nats',
    'incoming_events',
    '{
        "source_type": "nats",
        "url": "nats://localhost:4222",
        "subject": "events.>",
        "durable_name": "pg-tide-consumer",
        "stream": "EVENTS",
        "ack_wait_secs": 30
    }'::jsonb
);

Configuration Reference

ParameterTypeDefaultDescription
source_typestringMust be "nats"
urlstringNATS server URL
subjectstringSubject filter (supports wildcards: *, >)
durable_namestringDurable 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 tracks progress, so messages are never lost. The inbox's deduplication mechanism (using JetStream's sequence number as the event ID) prevents duplicates even on redelivery.

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