0

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?.

astrowalker
  • 3,123
  • 3
  • 21
  • 40

2 Answers2

1

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.

somdoron
  • 4,653
  • 2
  • 16
  • 24
0

If you want synchronous request/response communication you can use REQ/REP sockets instead of DEALER/ROUTER.

If you want asynchronous communication and you need to match responses to request, you can send a unique request ID in the request and return this request ID in the response.

rveerd
  • 3,620
  • 1
  • 14
  • 30
  • Well, I am already sending IDs back and forth, but it is **my** data, correct? I.e. ZeroMQ does not handle them, right? So I still need to come up with some algorithm to match those IDs. – astrowalker Sep 27 '16 at 07:49
  • 1
    That's correct, you need to match responses to requests. – rveerd Sep 27 '16 at 21:07