zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.62k stars 2.35k forks source link

Asynchronous ROUTER/DEALER without loosing Request/Reply association #4511

Open Placeblock opened 1 year ago

Placeblock commented 1 year ago

Please use this template for reporting suspected bugs or requests for help.

Issue description

I want to create a ROUTER Server that acts like an asynchronous REPLY Socket. However I also want to create an client that acts like a asynchronous REQUEST Socket. (Like described in the docs: https://zguide.zeromq.org/docs/chapter3/#The-DEALER-to-ROUTER-Combination)

The problem I am facing is that i still want to associate a Reply from the Server to a Request from the client. (Isn't that the reason why you use Req/Rep?) It seems like the whole Request / Reply pattern gets lost, which is obvious as you can send as many requests as fast as you want and get responses in no meaningful order because everything is asynchronous.

I would have to implement some sort of request id which is contained in my response too. Then I could associate a response with the according request if I save the id in the client. Is there a better solution or do I have to implement all this by myself?

In the same section in the docs it says (cite):

Because both DEALER and ROUTER can work with arbitrary message formats, if you hope to use these safely, you have to become a little bit of a protocol designer. At the very least you must decide whether you wish to emulate the REQ/REP reply envelope. It depends on whether you actually need to send replies or not.

I am not sure if this describes another problem or if I've just not understood it correctly.

Have a great day 😃