Webhook icon
Schedule icon
If icon
Log icon
Fail icon
Request icon
OutputValues icon
SlackIncomingWebhook icon
Set icon
Pause icon

Guard JetStream Redeliveries and In-Flight Acknowledgments

Monitor JetStream consumer redeliveries, ACK pressure and backlog with Kestra; approve a bounded pause without acknowledging or deleting messages.

Categories
DataInfrastructure

A JetStream durable consumer can keep a backlog while its workers repeatedly receive the same unacknowledged messages. This flow reads consumer state through NATS request/reply, reports transitions once, and lets an operator briefly pause delivery to repair a worker. It never pulls, acknowledges, resets, purges, or deletes messages.

How it works

  1. validate_scope (If) rejects unsafe stream/consumer tokens and nonpositive thresholds.
  2. inspect_consumer (NATS Request) queries $JS.API.CONSUMER.INFO.<stream>.<consumer>; check_info_reply rejects a JSON API error even when request/reply succeeded.
  3. snapshot exposes redelivered, ACK-pending, backlog, ACK limit, delivery/ACK floors, and paused state. classify exposes the observed status as outputs.classify.values.status, while previous_state captures the prior KV value as outputs.previous_state.values.status.
  4. change_only compares a per-consumer Kestra KV marker, sends one Slack transition alert, and records the new status.
  5. On a new degraded state, approve_pause (Pause) offers REPORT_ONLY or PAUSE_5_MIN. If approved, recheck_consumer reads the durable again. Only still-degraded, not-already-paused consumers receive $JS.API.CONSUMER.PAUSE with a five-minute deadline. verify_pause_reply checks NATS confirmation.

Error handling

  • NATS network requests retry with exponential backoff. A missing consumer, API error, empty response, or wrong identity fails before a pause request. nats_url must not contain embedded credentials.
  • The approval is bound to the named stream/consumer and a fresh health check. If conditions changed, the mutation is skipped.
  • A pause expires on the server after five minutes; ACKs for in-flight work remain possible. The flow never ACKs unprocessed messages.
  • The errors handler names the execution and points the operator to NATS consumer info and Kestra logs.

What this blueprint teaches about Kestra

  • A non-core NATS Request task can query JetStream's native management subjects without introducing an HTTP monitoring port.
  • KV state suppresses repeated alerts while the flow's machine-readable counters remain available on every execution.
  • A Pause followed by a new NATS read prevents stale human approval from acting on recovered or already-paused state.

Prerequisites

  • NATS Server 2.11 or later with JetStream enabled; a pre-existing durable consumer using explicit acknowledgments.
  • Kestra worker connectivity and NATS permissions to request consumer INFO and (if using approval) PAUSE subjects.
  • A Slack incoming webhook; replace the demo webhook trigger key.

Secrets

  • SLACK_WEBHOOK_URL: incoming webhook for state changes and failures. Add NATS credentials as secret() properties on both NATS Request tasks if your server requires authentication.

Inputs

  • nats_url (STRING, default nats://nats:4222): worker-reachable NATS address.
  • stream (STRING, default ORDERS) and consumer (STRING, default workers): exact existing durable identity.
  • redelivery_threshold (INT, default 1), ack_pending_threshold (INT, default 10), backlog_threshold (INT, default 100): positive pressure limits.
  • offer_pause (BOOL, default true): allow an operator to approve a bounded delivery pause.

Outputs

  • status (STRING): HEALTHY, DEGRADED, or UNKNOWN if the execution fails before classification.
  • counters (JSON): the observed consumer identity, counts, limits, sequence floors, and paused flag.

Quick start

  1. Start NATS with -js; create ORDERS and an explicit-ACK durable named workers. Add SLACK_WEBHOOK_URL to Kestra secrets.
  2. Run with defaults after pointing nats_url at the server. With no messages, status is HEALTHY and all three pressure counts are zero.
  3. Deliver a message to the worker without ACKing it, then run again. At the default redelivery threshold, a redelivery produces a single DEGRADED alert and an optional approval.
  4. Enable the schedule only after changing the webhook key and tuning thresholds to your workload.

Plugins used

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.