If I send request (frame) B and receive response, while at the same time I am already waiting for response for the previous request (A), the received response in B task, is in fact a response for A request:
request A sent
request B sent
request B processed (quick)
response B sent
response B received (*)
...
request A processed (slow)
response A sent
response A received
With naive matching I would get at point (*) a match request A--response B.
So how to synchronize them? I.e. I would like to end request A with response A, and request B with response B no matter how long does it take to handle each request. For the record I am using dealer-router sockets.
I am thinking about creating pool requests (Dictionary
) with task completion token bound to each request sent. A task creates new slot in the pool, sends requests and awaits the completion. In the background there is task running all the time -- a receiver -- it simply receives the responses, put each response in appropriate slot and sets given task token as completed. Am I on the right track, am I wrong, or it is already implemented in NetMQ?.
Read about the AsyncSocket pattern in my blog:
http://somdoron.com/2014/08/netmq-asp-net/
It has an example with TaskCompletionSource, sequence for each request and dictionary.