[zeromq-dev] Need help with Request-Reply Message Broker

Ian Barber ian.barber at gmail.com
Wed Aug 15 15:44:40 CEST 2012

On Tue, Aug 14, 2012 at 12:11 PM, Chernyshev Vyacheslav <astellar at ro.ru> wrote:
> Hello.
> I'm currently trying to use zeromq as a message-passing layer in a
> single process to deliver messages from clients to worker threads that
> represent a single service. Each client's request results in either 0 or
> 1 reply from server. After reading the guide I still have something
> unclear. As I understood, in case of REQ-REP message broker, we have
> fully synchronous communication between clients and worker threads, that
> means handling of one message at a time and sending empty replies in
> some cases just to keep REQ socket happy. In case of ROUTER-DEALER
> solutions we have fully asynchronous communication, where messages from
> single client are processed in arbitrary order. But what should I do if
> I want to ensure that messages from client are processed in the same
> order they are received without rolling back to single message at a time?

The arbitrary order you mention would only be if introduced by your
app - if you send two messages over the same connection from the same
client, they will appear to the consuming application in the proper
order. The async aspect would arise if you, say, sent 3 messages to a
multi-thread or multi-process system where message 1 takes longer to
process than 2 and 3, you might get the replies out of order, but in a
single-process environment that wont happen.

If that is likely, then just include an ID as a message part in your
messages, and match reply to request when it is returned. Similarly,
if you have multiple connections pushing messages from the same
client, then I would use a sequence number and push into a buffer if
the messages arrive out of order.


More information about the zeromq-dev mailing list