NATS Core Publish icon

NATS Core Publish

Sends messages to a NATS.io Server

Overview

This node publishes messages to a NATS.io server, a high-performance messaging system used for cloud-native applications, microservices, and distributed systems. It is useful when you want to send real-time messages or events to other services or components subscribed to specific subjects (topics) on the NATS server.

Typical use cases include:

  • Broadcasting notifications or events to multiple subscribers.
  • Sending commands or data updates in microservice architectures.
  • Integrating with event-driven workflows where message queuing and delivery are required.

For example, you can publish JSON-formatted sensor data to a subject named "sensors.temperature" so that any service listening to this subject receives the latest readings.

Properties

Name Meaning
Subject The name of the queue or subject to which the message will be published.
Message The content of the message to send. Can be a plain string or JSON (if "JSON Parameters" is set).
JSON Parameters Boolean flag indicating if the "Message" field contains JSON text that should be parsed.
Send Input Data Whether to send the incoming input data (from previous nodes) as JSON instead of the "Message".
Queue Group Name The name of the queue group to use (currently logged but not functionally used in publishing).

Output

The node outputs the same number of items as it receives as input, each containing a json property with the message that was published. If the message was sent as JSON, the output reflects the parsed object; otherwise, it outputs the string message.

No binary data output is produced by this node.

Example output item JSON structure:

{
  "json": {
    /* The published message content, either an object or string */
  }
}

Dependencies

  • Requires connection to a NATS.io server, specified via credentials including the server URL and optionally authentication using NKey credentials.
  • Uses the official NATS Core client libraries (@nats-io/nats-core and @nats-io/transport-node) for communication.
  • Requires an API key credential configured in n8n for connecting securely to the NATS server.

Troubleshooting

  • Connection issues: Ensure the NATS server URL is correct and accessible from the n8n instance. Verify network connectivity and firewall settings.
  • Authentication errors: If using NKey authentication, confirm that the NKey seed and public key are valid and correctly configured.
  • Invalid JSON: When "JSON Parameters" is enabled, the "Message" must be valid JSON. Invalid JSON will cause parsing errors.
  • Empty subject: The "Subject" property is required; leaving it empty will cause the node to fail.
  • Unhandled exceptions: If the node encounters an error during publishing, it will throw an error unless "Continue On Fail" is enabled, in which case it adds an error object to the output.

Links and References

Discussion