NATS icon

NATS

NATS

Overview

This node integrates with the NATS messaging system, allowing users to publish messages to NATS subjects. It is useful in scenarios where you want to send notifications, events, or data streams to other services or microservices subscribed to specific NATS subjects. For example, it can be used to trigger workflows in distributed systems, send real-time updates, or push logs and metrics.

The node supports sending payloads as either plain strings or binary data, with options to customize headers and control how replies from the service are handled (e.g., requesting multiple replies, setting timeouts).

Properties

Name Meaning
Subject The NATS subject (topic) to which the message will be published.
Payload Content Type The type of the payload content; options are: "String" or "N8n Binary Data".
Payload The actual message content as a string (used if Payload Content Type is "String").
Payload Binary Property Name The name of the binary property containing the payload data (used if Payload Content Type is "N8n Binary Data").
Headers Optional HTTP-like headers to include with the message, specified as key-value pairs.
Options Collection of additional options:
- Content Is Binary Whether to save the content as binary data.
- JSON Parse Body Whether to parse the response body as JSON object.
- Max Replies Maximum number of replies to receive from the service.
- Only Content Whether to return only the content property from the response.
- Request Many Whether to request multiple replies from the service.
- Timeout Maximum timeout duration (in milliseconds) to wait for incoming replies.

Output

The node outputs an array of items, each containing a json field with the response data from the NATS service. Depending on the options set:

  • If onlyContent is true, the output contains only the content part of the response.
  • If contentIsBinary is true, the content may be saved as binary data.
  • If jsonParseBody is enabled, the response body is parsed into a JSON object.

The output structure generally includes the message reply or acknowledgment received from the NATS server after publishing.

Dependencies

  • Requires a connection to a NATS server, configured via an API key or authentication token credential.
  • Uses an internal NATS service client to manage connections and message publishing.
  • No external environment variables are explicitly required beyond the credential setup.

Troubleshooting

  • Connection errors: Ensure that the NATS server URL and credentials are correctly configured and accessible.
  • Timeouts: If no replies are received within the specified timeout, consider increasing the timeout value or verifying the NATS server responsiveness.
  • Payload issues: When sending binary data, ensure the correct binary property name is provided and that the data exists in the input item.
  • Parsing errors: If jsonParseBody is enabled but the response is not valid JSON, parsing will fail. Disable this option or verify the response format.
  • Error handling: If continueOnFail is disabled, any error during message publishing will stop execution. Enable it to collect errors per item instead.

Links and References

Discussion