[zeromq-dev] sending and receiving multiple messages and replies from same thread

Hamed Afshar hamed_afshar at yahoo.com
Wed May 15 15:46:43 CEST 2013

Thanks for your reply,
In my use case, the client requests are sequential and depend on each other. which means when server receives a request from the client, it will decide what to do based on previous requests received from that client. Also, each request must have a reply and the client will send next request based on the reply receives from the server.

Right now, I am using the example provided in the online guide. (http://zguide.zeromq.org/pl:mtserver)
This example almost do what I want, but in the following line, it asks for a round robin queue:
zmq_device (ZMQ_QUEUE, $clients, $workers);

Is there any way to implement my own queuing algorithm instead of ZMQ_QUEUE?


 From: Pieter Hintjens <ph at imatix.com>
To: Hamed Afshar <hamed_afshar at yahoo.com>; ZeroMQ development list <zeromq-dev at lists.zeromq.org> 
Sent: Wednesday, May 15, 2013 5:45 PM
Subject: Re: [zeromq-dev] sending and receiving multiple messages and replies from same thread

Two answers here. The first is, read the Guide or buy the ZeroMQ book
from O'Reilly, work through the examples, and you'll learn what you

Second answer: what you are trying to do is probably wrong (and this
is very common for people who haven't yet digested how 0MQ works).
Creating one thread per client is a classic BSD socket pattern but not
common for 0MQ apps. You don't explain enough about your use-case to
know what the right direction is.

So I'd really suggest reading the Guide and building enough throw-away
examples to internalize the way it all works. Then, probably a ROUTER
for the server, a DEALER for the clients.


On Wed, May 15, 2013 at 2:14 PM, Hamed Afshar <hamed_afshar at yahoo.com> wrote:
> Hi,
> I want to use zeromq for the following scenario, but can't recognize the
> proper pattern for this.
> Server listens to port 5555. When a client connects to server, thread A
> handles this connection and from now on, every request from client goes to
> thread A, and thread A sends a reply to the client.
> Currently, I am using normal req/rep pattern with Router/Dealer on top to
> handle multithreading. but every request from a client is round robined and
> load balanced between thread. What I need, is that when a thread answers the
> first request from a client, from now on, the same thread answer the rest of
> the requests from that client. (like having a persistent connection with
> client).
> Is this scenario possible with ZMQ? if yes, how?
> Thank you very much for your assistance,
> Jerry
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130515/8f86b7f6/attachment.htm>

More information about the zeromq-dev mailing list