Nats icon

Nats

Sends messages to a Nats

Overview

This n8n node allows you to send messages to a NATS server (a high-performance messaging system). It supports sending either the input data received by the node or a custom message, with optional headers and configuration options. The node is useful for integrating n8n workflows with systems that use NATS for event-driven communication, such as microservices architectures, real-time notifications, or distributed task processing.

Practical examples:

  • Forwarding processed data from an n8n workflow to a NATS subject for downstream services.
  • Sending alerts or notifications to a NATS-powered system.
  • Integrating n8n with legacy or custom applications that communicate via NATS.

Properties

Name Type Meaning
Subject string Name of the NATS subject (queue/topic) to publish the message to.
Send Input Data boolean If true, sends the incoming JSON data as the message; if false, uses the "Message" field.
Message string The message content to send (used only if "Send Input Data" is false).
JSON Parameters boolean If true, headers are provided as a JSON object; if false, use the UI collection.
Headers fixedCollection Key-value pairs for message headers (shown if "JSON Parameters" is false).
Headers (JSON) json Flat JSON object for headers (shown if "JSON Parameters" is true).
Options → Only Emit boolean If true, sends the message without waiting for a response from NATS.

Output

The node outputs an array of objects in the json field. The structure depends on the operation:

  • On success:
    [
      {
        "success": true
      }
    ]
    
  • On error (if "Continue On Fail" is enabled):
    [
      {
        "error": "Error message"
      }
    ]
    
  • If waiting for a response:
    Each output item will contain the decoded response data from NATS in the data property:
    [
      {
        "data": { /* response from NATS */ }
      }
    ]
    

Binary data is not produced by this node.

Dependencies

  • NATS Server: You must have access to a running NATS server.
  • Credentials: Requires n8n credentials of type natsApi, including:
    • servers: Comma-separated list of NATS server addresses.
    • timeout: Connection timeout.
    • authentication (optional): Username and password if authentication is required.
  • n8n Configuration: No special environment variables beyond credentials.

Troubleshooting

Common issues:

  • Authentication errors: If username/password are missing when authentication is enabled, you'll see an error:
    "Username and password are required for authentication"

    • Resolution: Ensure both fields are filled in your credentials.
  • Invalid headers JSON: If the "Headers (JSON)" field contains invalid JSON, you'll get:
    "Headers must be a valid json"

    • Resolution: Check your JSON syntax.
  • Connection errors: If the node cannot connect to the NATS server, check your server address, network connectivity, and credentials.

  • No response from NATS: If "Only Emit" is false and no response is received, ensure the NATS subject is set up to reply.

Links and References

Discussion