Skip to content

feat(inputs.nats_consumer): add durable consumer support for JetStream#18720

Open
aleksclark wants to merge 2 commits intoinfluxdata:masterfrom
aleksclark:feat/nats-durable-consumer
Open

feat(inputs.nats_consumer): add durable consumer support for JetStream#18720
aleksclark wants to merge 2 commits intoinfluxdata:masterfrom
aleksclark:feat/nats-durable-consumer

Conversation

@aleksclark
Copy link
Copy Markdown

@aleksclark aleksclark commented Apr 15, 2026

Summary

Add durable consumer support to the NATS JetStream input plugin, allowing consumers to survive Telegraf restarts without message loss or replay.

The existing JetStream support uses ephemeral push consumers. When Telegraf restarts, the consumer is lost and messages may be replayed from the beginning of the stream or missed entirely. Durable consumers persist on the NATS server and resume from where they left off.

New Configuration Options

Option Type Default Description
jetstream_durable_name string "" Durable consumer name — survives restarts
jetstream_deliver_policy string "all" Where to start: all, last, new, by_start_sequence, by_start_time
jetstream_start_sequence uint64 0 Starting sequence for by_start_sequence policy
jetstream_start_time string "" RFC3339 start time for by_start_time policy
jetstream_ack_wait duration 30s Server-side ack timeout before redelivery
jetstream_max_deliver int -1 Max redelivery attempts (-1 = unlimited)
jetstream_filter_subjects []string [] Filter subjects within a stream
jetstream_consumer_name string "" Explicit consumer name for pre-created consumers

Behavior Changes

  • When durable_name is set, uses Drain() instead of Unsubscribe() on shutdown to preserve the consumer
  • Correctly uses js.Subscribe() when no queue group is set, instead of always using QueueSubscribe()

Tests

  • 6 new integration tests covering: durable restart resilience, deliver policies (new, by_start_sequence), max deliver limits, filter subjects, and durable + queue group combinations
  • All tests use testcontainers with the official nats Docker image

Files Changed

  • plugins/inputs/nats_consumer/nats_consumer.go — New config fields + subscription options
  • plugins/inputs/nats_consumer/nats_consumer_test.go — 6 new integration tests (580 lines)
  • plugins/inputs/nats_consumer/sample.conf — New config options documentation
  • plugins/inputs/nats_consumer/README.md — Updated documentation

Checklist

Related issues

resolves #18734

Add support for durable JetStream consumers that survive Telegraf restarts,
preventing message loss or replay. New config options:

- jetstream_durable_name: bind to a named durable consumer
- jetstream_deliver_policy: control where in the stream to start (all, last, new, by_start_sequence, by_start_time)
- jetstream_start_sequence / jetstream_start_time: for sequence/time-based delivery
- jetstream_ack_wait: server-side ack timeout before redelivery
- jetstream_max_deliver: max redelivery attempts per message
- jetstream_filter_subjects: filter subjects within a stream
- jetstream_consumer_name: explicit consumer name for pre-created consumers

When durable_name is set, subscriptions use Drain() instead of
Unsubscribe() on shutdown to preserve the consumer on the server.
The plugin also now uses js.Subscribe() when no queue group is set,
instead of always using QueueSubscribe().

🐨 Generated with Crush

Assisted-by: AWS Claude Opus 4.6 via Crush <crush@charm.land>
@telegraf-tiger
Copy link
Copy Markdown
Contributor

Thanks so much for the pull request!
🤝 ✒️ Just a reminder that the CLA has not yet been signed, and we'll need it before merging. Please sign the CLA when you get a chance, then post a comment here saying !signed-cla

@telegraf-tiger telegraf-tiger bot added feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Apr 15, 2026
@aleksclark
Copy link
Copy Markdown
Author

!signed-cla

🐘 Generated with Crush

Assisted-by: AWS Claude Opus 4.6 via Crush <crush@charm.land>
@telegraf-tiger
Copy link
Copy Markdown
Contributor

@srebhan
Copy link
Copy Markdown
Member

srebhan commented Apr 17, 2026

@aleksclark can you please restore the PR description template, especially the AI section, as we cannot review your PR otherwise!

@srebhan srebhan self-assigned this Apr 17, 2026
@srebhan srebhan added the waiting for response waiting for response from contributor label Apr 17, 2026
@aleksclark
Copy link
Copy Markdown
Author

@srebhan sure thing, sorry about that!

@telegraf-tiger telegraf-tiger bot removed the waiting for response waiting for response from contributor label Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(inputs.nats_consumer): add durable consumer support for JetStream

2 participants