Overview
This node is designed to publish messages to a message broker using a topic exchange pattern, typically in an event-driven architecture. It allows users to send custom messages with flexible routing keys and payloads, making it useful for integrating different systems or services that communicate asynchronously via messaging.
Common scenarios include:
- Sending event notifications to other microservices.
- Triggering workflows based on specific events.
- Broadcasting messages to multiple consumers subscribed to certain topics.
For example, you might use this node to publish an "order.created" event with order details as the payload, which other services can listen to and react accordingly.
Properties
| Name | Meaning |
|---|---|
| Routing Key Prefix | The prefix added before the defined pattern, separated by a dot, forming part of the routing key. |
| Wait for Reply | Boolean flag indicating whether the node should wait for a reply message after publishing. |
| Exchange | The name of the exchange to which the message will be published (default: "cqrs"). |
| Exchange Type | The type of the exchange; hidden property set to "topic". |
| Options | Additional options for the queue and message publishing, including: |
| - Alternate Exchange: fallback exchange if the main exchange cannot route the message. | |
| - Arguments: key-value pairs for advanced AMQP options. | |
| - Auto Delete Queue: whether the queue deletes itself when no consumers remain. | |
| - Durable: whether the queue survives broker restarts. | |
| - Headers: custom headers to add to the message. | |
| Pattern | The suffix pattern appended to the routing key prefix to form the full routing key (required). |
| Payload | The JSON payload to send with the message (required). |
| Spread Response | If true and the response is an array, each item will be output as a separate item instead of one array. |
Output
The node outputs JSON data representing the response from the message broker or the result of the publish operation. If the "Wait for Reply" option is enabled, the node waits for a reply message and outputs its content.
If the response is an array and "Spread Response" is enabled, each element of the array is emitted as an individual item.
The node does not explicitly handle binary data output.
Dependencies
- Requires connection to a message broker supporting AMQP protocol (e.g., RabbitMQ).
- Needs configuration of an API key or authentication token for the message broker connection within n8n credentials (not shown in the source).
- Uses a topic exchange named by default "cqrs" but configurable.
Troubleshooting
- Connection errors: Ensure the message broker is reachable and credentials are correctly configured.
- Routing issues: Verify that the routing key prefix and pattern combine correctly to match existing bindings in the exchange.
- No reply received: If "Wait for Reply" is enabled but no response arrives, check that the consumer service sends replies properly and that queues are correctly set up.
- Invalid payload: Make sure the JSON payload is well-formed and matches expected schema by the receiving service.
- Exchange or queue misconfiguration: Use the options to configure durable queues and alternate exchanges to avoid message loss.