Overview
This node acts as a trigger that subscribes to messages on specified NATS subjects. It listens for incoming messages matching a subject pattern and triggers workflows when such messages arrive. This is useful in event-driven architectures where workflows need to respond to real-time events published on a NATS messaging system.
Common scenarios include:
- Reacting to order updates or new user signups by subscribing to relevant subjects.
- Load balancing message processing across multiple subscribers using queue groups.
- Integrating NATS-based microservices with n8n workflows for automation.
For example, subscribing to the subject orders.> will trigger the workflow whenever any message related to orders (including subtopics) is published.
Properties
| Name | Meaning |
|---|---|
| Subject | Subject pattern to subscribe to (no spaces allowed). Supports wildcards: * for single token, > for multi-token wildcard. Example: orders.> subscribes to all subjects starting with "orders." |
| Queue Group | Optional group name for load balancing multiple subscribers. Only one subscriber in the group receives each message. Example: order-processors |
Output
The node outputs JSON data representing the received NATS message. The structure includes:
subject: The subject string of the message.data: The payload of the message, which can be any JSON object.headers: Metadata headers associated with the message.replyTo: A reply inbox string if applicable.timestamp: ISO timestamp of when the message was received.
If triggered manually (for testing), it emits a sample message with fields like id, message, type, user info, metadata, and timestamp.
The output does not include binary data.
Dependencies
- Requires a connection to a NATS server via an API key credential.
- Needs proper configuration of the NATS server credentials within n8n.
- Uses internal utility modules for managing NATS connections and message parsing.
Troubleshooting
- Failed to setup NATS subscriber: Indicates issues connecting to the NATS server. Check network connectivity, credentials, and server availability.
- Subscriber connection lost / disconnected: The node logs warnings/errors when the connection drops. Ensure stable network and valid permissions.
- Permission errors: May occur if the API key lacks rights to subscribe to the requested subject. Verify access control on the NATS server.
- Invalid subject or queue group: The node validates these inputs; ensure no spaces and correct wildcard usage.