ZeroMQ Sockets

1314462038|%e %B %Y, %H:%M
Tags zeromq

Back to list of posts

ZeroMQ provides a scaleability layer between application endpoints. It implements several different message topologies, provided by a series of Socket Types, each with their own well-defined function and behaviour. This article summaries the behaviour and function of each Socket Type, and the most typical Socket combinations, valid in ZeroMQ 2.1.x.

ZeroMQ Socket Types

Socket Topology Send/Receive Incoming Routing / Msg Action Outgoing Routing / Msg Action HWM Action
REQ Request-Reply Send, Receive, Send, … Last peer /
Removes empty part
Load balanced /
Prepends empty part, queue unsent msgs
Block
REP Request-Reply Receive, Send, Receive, … Fair-queued /
Retains message parts up to 1st empty part
Last peer /
Prepends retained parts, queue unsent msgs
Drop
DEALER Request-Reply Unrestricted Fair-queued /
No changes made
Load-balanced /
No changes made, queue unsent msgs
Block
ROUTER Request-Reply Unrestricted Fair-queued /
Prepends reply address to message
Addressed peer /
Strips 1st message part, drops message if identity not known or peer available
Drop
PUB Pub-Sub Send only n/a Fan out /
No changes made, drops message if no subscribers
Drop
SUB Pub-Sub Receive only Fair-queued, optional filtering /
No changes made
n/a Drop
PUSH Pipeline Send only n/a Load balanced /
No changes made, queue unsent msgs
Block
PULL Pipeline Receive only Fair-queued /
No changes made
n/a n/a
PAIR Exclusive Pair Unrestricted n/a Queue unsent msgs Block

Where:

  • Fair-queued means the socket gets input from all sockets connected to it in turn.
  • Load-balanced means the socket sends messages to all sockets connected to it in turn.
  • Last peer means the socket sends the message to the last socket that sent it a message
  • Fan-out means message is sent to all connected peers simultaneously

ZeroMQ Socket Combinations

ZeroMQ only supports the following Socket combinations in a connect-bind pair:

Combination Examples from the ZeroMQ ZGuide [1]
PUB and SUB Uni-directional message broadcast from Publisher to Subscriber(s)
Publish-Subscribe Proxy Server
Slow Subscribers (Suicidal Snail Pattern)
High-speed Subscribers (Black Box Pattern)
Reliable Pub-Sub shared key-value system (Clone Pattern)
REQ and REP Sequential message request-reply between two Endpoints (e.g. client to server)
REQ and ROUTER Frontend broker connection to multiple clients
Req-rep broker connection to multiple workers using custom routing (LRU)
DEALER and REP Simple synchronous (one request , one reply) broker connection to one or more separate worker processes using load-balancing DEALER socket
DEALER and ROUTER Custom 1 .. n request routing from a single client to multiple servers
Asynchronous n..1 request routing to a single server
DEALER and DEALER Backend asynchronous (one request, many replies) broker connection to multiple workers
ROUTER and ROUTER Asynchronous brokerless reliability (Freelance Pattern)
PUSH and PULL Task ventilator connected to a pool of workers that forward results to a task sink
Parallel Pipeline with kill signalling
Pipeline streamer device
PAIR and PAIR Signalling between Threads

Comments: 0

Add a New Comment

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License