ZeroMQ icon

ZeroMQ

Sends or receives ZeroMQ messages as a one-time action

Actions2

Overview

This node enables sending and receiving messages using ZeroMQ sockets, a high-performance asynchronous messaging library. It supports various socket types such as Request-Reply, Publish-Subscribe, Push-Pull patterns, allowing flexible communication setups.

The Receive operation listens for incoming messages on specified ZeroMQ socket types (pull, sub, or rep). It can act either as a server (bind) or client (connect) to a given socket address. For subscription sockets, it supports filtering by topic. For reply sockets, it automatically sends a configured response after receiving a message.

Use cases:

  • Receiving task messages from distributed workers via Pull sockets.
  • Subscribing to published events filtered by topic.
  • Implementing request-reply patterns where the node replies automatically upon receiving requests.

Properties

Name Meaning
Socket Type The type of ZeroMQ socket to use. Options: Request (REQ), Reply (REP), Publish (PUB), Subscribe (SUB), Push, Pull. For Receive operation, valid types are Pull, Subscribe, and Reply.
Action Whether to bind (act as server and listen) or connect (act as client) to the socket address. Options: Bind, Connect.
Socket Address The ZeroMQ socket address to bind or connect to, e.g., tcp://127.0.0.1:5555.
Topic (Only for Subscribe socket) The topic to subscribe to. Leave empty to receive all topics.
Response (for REP) (Only for Reply socket) The automatic response message sent after receiving a message. Default is "ACK".

Output

The node outputs an array of JSON objects representing received messages. The structure depends on the socket type:

  • Subscribe (SUB):

    {
      "topic": "<received_topic>",
      "message": "<received_message>"
    }
    
    • topic: The topic string of the received message.
    • message: The message content following the topic.
  • Pull (PULL):

    {
      "message": "<received_message>"
    }
    
    • message: The received message content.
  • Reply (REP):

    {
      "message": "<received_message>"
    }
    
    • message: The received request message. The node automatically sends back the configured response.

No binary data output is produced by this node.

Dependencies

  • Requires the zeromq Node.js package for ZeroMQ socket communication.
  • No special n8n credentials are required, but the node needs network access to the specified ZeroMQ socket addresses.
  • Ensure that the ZeroMQ environment (servers or peers) is properly set up and accessible.

Troubleshooting

  • Invalid socket type error:
    If you select a socket type not supported for the Receive operation (only pull, sub, and rep are valid), the node will throw an error. Make sure to choose a compatible socket type.

  • Connection issues:
    Binding or connecting to an invalid or unreachable socket address will cause errors or timeouts. Verify the socket address format and network connectivity.

  • Subscription topic filtering:
    If no messages are received on a Subscribe socket, check if the topic filter matches the published topics. Leaving the topic empty subscribes to all messages.

  • Automatic response in Reply socket:
    The node sends a fixed response after receiving a message on a Reply socket. If the peer expects a different protocol or response, communication may fail.

  • Resource cleanup:
    The node closes the socket after receiving one message. For continuous listening, consider looping or triggering the node repeatedly.

Links and References

Discussion