NATS JetStream icon

NATS JetStream

Manage NATS JetStream streams, consumers, and publish messages

Actions11

Overview

This node manages NATS JetStream consumers, specifically allowing the creation of consumers on existing JetStream streams. It is useful in scenarios where you want to set up message consumers that process or react to messages published on a JetStream stream. For example, you might create a durable consumer to reliably process order events from an "EVENTS" stream, ensuring messages are acknowledged and redelivered if necessary.

The "Create Consumer" operation lets you configure various aspects of the consumer such as delivery policy, acknowledgment behavior, filtering subjects, and retry limits, enabling fine-grained control over how messages are consumed.

Properties

Name Meaning
Stream Name Name of the JetStream stream on which the consumer will be created. The stream must already exist.
Consumer Configuration A collection of settings for the consumer:
- Consumer Name: Name of the consumer; required for durable consumers, leave empty for ephemeral consumers.
- Durable Name: Durable consumer name (persists across restarts).
- Description: Human-readable description.
- Delivery Policy: When to deliver messages:
  • All
  • By Start Sequence
  • By Start Time
  • Last
  • Last Per Subject
  • New
- Acknowledgment Policy: How acknowledgments are handled:
  • Explicit
  • All
  • None
- Filter Subject: Subject pattern to filter messages received by this consumer.
- Start Sequence: Starting sequence number (if delivery policy is "By Start Sequence").
- Start Time: Starting timestamp in ISO format (if delivery policy is "By Start Time").
- Acknowledgment Wait (Seconds): Time to wait for ack before redelivery.
- Max Deliver: Maximum delivery attempts (-1 means unlimited).
- Max Ack Pending: Max number of outstanding acknowledgments.
- Max Waiting: Max number of outstanding pull requests.
- Number of Replicas: Number of replicas for the consumer (0 inherits from stream).

Output

The node outputs JSON data representing the result of the consumer creation operation. This typically includes details about the newly created consumer such as its configuration and status as returned by the JetStream management API.

No binary data output is produced by this operation.

Example output JSON structure (simplified):

{
  "name": "order-processor",
  "stream_name": "EVENTS",
  "config": {
    "deliver_policy": "all",
    "ack_policy": "explicit",
    "filter_subject": "events.orders.>",
    "ack_wait": 30,
    "max_deliver": -1,
    ...
  },
  "created": "2024-01-01T12:00:00Z"
}

Dependencies

  • Requires a connection to a NATS server with JetStream enabled.
  • Needs an API key credential or equivalent authentication configured in n8n to connect securely to the NATS server.
  • Uses the bundled nats client library for communication with JetStream.
  • No additional external services are required beyond the NATS JetStream server.

Troubleshooting

  • Common Issues:

    • Stream does not exist: The specified stream name must exist before creating a consumer. Ensure the stream is created and available.
    • Invalid subject filter: The filter subject must be a valid NATS subject pattern.
    • Incorrect durable name usage: Durable name is required for durable consumers; leaving it empty creates ephemeral consumers.
    • Connection errors: Verify network connectivity and credentials to the NATS server.
  • Error Messages:

    • "Unknown consumer operation: create": Indicates the operation parameter is incorrect or unsupported.
    • "NATS JetStream operation failed: ...": General failure connecting or performing the operation; check credentials and server availability.
    • Validation errors related to parameters like start time format or sequence numbers.
  • Resolutions:

    • Double-check all input parameters for correctness.
    • Confirm the stream exists and is accessible.
    • Validate date/time formats for start time.
    • Ensure proper authentication credentials are configured in n8n.

Links and References

Discussion