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
| Parameter | Type | Default | Description |
|---|---|---|---|
source_type | string | — | Must be "nats" |
url | string | — | NATS server URL |
subject | string | — | Subject filter (supports wildcards: *, >) |
durable_name | string | — | Durable consumer name for offset tracking |
stream | string | null | JetStream stream name |
ack_wait_secs | int | 30 | Seconds before unacknowledged messages are redelivered |
credentials_file | string | null | NATS credentials file |
batch_size | int | 100 | Messages 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
- Sinks: NATS — Publishing to NATS (forward direction)
- Bidirectional Sync — Two-way NATS communication