Overview
This node integrates with a NATS messaging system, specifically providing the ability to publish messages to a NATS server. It is useful in scenarios where you want to send messages or events to other services or microservices that subscribe to specific subjects on a NATS server. For example, it can be used to trigger workflows or notify other systems asynchronously by publishing messages with custom payloads and headers.
The "Publish" operation sends a message to a specified subject on the NATS server. Users can define the message content as either a string or binary data, add custom headers, and configure options such as parsing JSON bodies, handling multiple replies, and setting timeouts.
Properties
Name | Meaning |
---|---|
Subject | The subject (topic) on the NATS server 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 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 (used if Payload Content Type is "N8n Binary Data"). |
Headers | Custom headers to include with the message; each header has a key and a value. |
Options: | Collection of additional options: |
- Content Is Binary | Whether to save the content as binary data. |
- JSON Parse Body | Whether to parse the body content into an object (useful if the payload is JSON). |
- Max Replies | Maximum number of replies to wait for from the service after publishing. |
- Only Content | Whether to return only the content property in the output instead of the full response. |
- Request Many | Whether to request multiple replies from services (enables receiving multiple responses). |
- Timeout | Maximum timeout duration (in milliseconds) to wait for incoming replies. |
Output
The node outputs JSON data representing the result of the publish operation. This typically includes any replies received from the NATS service if configured to wait for them. If the option "Only Content" is enabled, the output will contain just the content part of the response.
If the payload or response involves binary data, the node handles this accordingly, allowing binary content to be saved or processed further within n8n workflows.
Dependencies
- Requires a connection to a NATS server.
- Needs an API authentication token or API key credential configured in n8n to authenticate with the NATS service.
- Uses an internal NATS service connection manager to handle connections.
- Depends on the
typedi
library for dependency injection and service management. - Relies on the
n8n-workflow
package for error handling and workflow integration.
Troubleshooting
- Connection Issues: Failure to connect to the NATS server may occur if credentials are incorrect or the server is unreachable. Verify network connectivity and credential correctness.
- Timeouts: If waiting for replies, ensure the timeout is set appropriately; otherwise, the node might throw timeout errors.
- Payload Format Errors: When using JSON parsing, invalid JSON payloads will cause errors. Validate JSON syntax before sending.
- Binary Data Handling: Incorrect binary property names or missing binary data can lead to empty or failed payloads.
- Error Handling: If "Continue On Fail" is disabled, any error during publishing will stop execution. Enable it to collect errors per item without stopping the entire workflow.