NATS JetStream icon

NATS JetStream

Manage NATS JetStream streams, consumers, and publish messages

Actions11

Overview

This node manages NATS JetStream resources, specifically streams, consumers, and messages. For the Stream Create operation, it allows users to create a new JetStream stream with detailed configuration options such as subjects to consume, storage type, retention policy, message limits, and replication settings.

Typical use cases include:

  • Setting up event streaming pipelines where messages are published to specific subjects and persisted according to business needs.
  • Creating durable streams for microservices communication or event sourcing.
  • Configuring streams with custom retention and storage policies to optimize resource usage and availability.

For example, you might create a stream named "EVENTS" that listens to subjects like events.orders and events.inventory, stores messages on disk, retains them based on limits, and replicates data for high availability.

Properties

Name Meaning
Stream Name The name of the JetStream stream to create. Should be descriptive to identify the stream's purpose.
Stream Configuration A collection of optional settings to configure the stream:
- Subjects: List of subjects this stream will consume (supports wildcards like events.* or events.>).
- Description: Human-readable description.
- Storage Type: Storage backend, either File (persistent) or Memory (non-persistent but faster).
- Retention Policy: How messages are retained (Limits, Interest, or Work Queue).
- Max Messages: Maximum number of messages stored (-1 for unlimited).
- Max Messages Per Subject: Max messages per subject (-1 for unlimited).
- Max Age (Seconds): Max age of messages in seconds (0 for unlimited).
- Max Bytes: Max total size in bytes (-1 for unlimited).
- Max Message Size: Max individual message size in bytes (-1 for unlimited).
- Discard Policy: Policy when limits are reached (Old to discard old messages, New to reject new messages).
- Number of Replicas: Number of replicas (1-5) for availability.
- Max Consumers: Max number of consumers (-1 for unlimited).
- Duplicate Window (Nanoseconds): Time window for duplicate detection (0 disables).
- No Acknowledgments: Whether to disable acknowledgments for the stream (boolean).

Output

The node outputs a JSON object representing the result of the stream creation operation. This typically includes details about the created stream such as its name, configuration, and status returned by the JetStream management API.

There is no binary output for this operation.

Example output structure (simplified):

{
  "name": "EVENTS",
  "config": {
    "subjects": ["events.orders", "events.inventory"],
    "storage": "file",
    "retention": "limits",
    "max_msgs": 100000,
    "max_bytes": 104857600,
    "num_replicas": 3,
    ...
  },
  "created": true
}

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 bundled NATS client libraries internally; no additional external dependencies required beyond proper credentials and network access.

Troubleshooting

  • Common issues:

    • Invalid or missing stream name: Ensure the "Stream Name" property is provided and valid.
    • Incorrect subject syntax: Subjects must follow NATS subject format; wildcards allowed but must be valid.
    • Insufficient permissions: The API key or credentials used must have rights to create streams on the NATS server.
    • Resource limits exceeded: Specifying too many replicas or message limits may cause errors if the server cannot accommodate.
  • Error messages:

    • "Unknown stream operation: create": Indicates the operation name is incorrect or unsupported; verify the operation parameter.
    • "NATS JetStream operation failed: ...": General failure connecting or executing the operation; check credentials, network connectivity, and server status.
    • Validation errors related to stream configuration fields usually indicate invalid values or types; review input properties carefully.

To resolve errors, verify all input parameters, ensure the NATS server is reachable and properly configured, and confirm credentials have necessary permissions.

Links and References

Discussion