CQRS Command Trigger icon

CQRS Command Trigger

CommandTrigger

Overview

This node implements a custom trigger based on a messaging pattern, specifically designed to listen for messages matching a routing key pattern in a message queue system. It is useful in scenarios where workflows need to be triggered by specific commands or events sent through a message broker, such as RabbitMQ.

For example, you might use this node to start a workflow whenever a particular command message arrives, identified by a routing key composed of a prefix and a user-defined pattern. This allows flexible and dynamic triggering based on message content or routing keys.

Properties

Name Meaning
Routing Key Prefix The prefix added before the defined pattern, separated by a dot. Defaults to "command".
Queue The name of the queue to listen on. If left empty, a unique queue name will be generated automatically.
Pattern The suffix pattern (without prefix) used to match routing keys for this custom operation. Required field.
Options Collection of additional options:
- Delete From Queue When Specifies when to acknowledge (delete) the message from the queue. Options:
- Execution Finishes: after workflow execution ends (success or failure).
- Execution Finishes Successfully: after successful workflow execution only.
- Immediately: as soon as the message is received.
- Specified Later in Workflow: manual acknowledgment via another node.
- JSON Parse Body Whether to parse the message body as JSON object. Default true.
- Only Content Whether to return only the content property of the message. Default true.
- Parallel Message Processing Limit Maximum number of concurrent executions allowed. Use -1 for unlimited. Only applies if acknowledgment is not immediate.

Output

The node outputs JSON data representing the message content received from the queue. Depending on the "Only Content" option, it either returns the entire message or just the content part. If "JSON Parse Body" is enabled, the message body is parsed into an object; otherwise, it remains raw.

No binary data output is indicated by the source code or properties.

Dependencies

  • Requires connection to a message queue service supporting routing keys and queues (e.g., RabbitMQ).
  • Needs appropriate credentials and configuration within n8n to connect to the message broker.
  • No other external dependencies are explicitly required.

Troubleshooting

  • Common issues:

    • Incorrect routing key pattern or prefix may cause no messages to trigger the workflow.
    • Leaving the queue name empty generates a unique queue each time, which may lead to unexpected behavior if persistent queues are needed.
    • Misconfiguration of acknowledgment timing can cause messages to be reprocessed or lost.
    • Parsing errors if the message body is not valid JSON but "JSON Parse Body" is enabled.
  • Error messages:

    • Errors related to connection failures to the message broker usually indicate credential or network issues.
    • Parsing errors will occur if the message body is malformed JSON when parsing is enabled; disabling JSON parsing or ensuring valid JSON input resolves this.

Links and References

Discussion