JustinTulloss/zeromq.node

How to receive a reply when using REQ socket?

Opened this issue · 3 comments

I am looking at some py bindings for zeromq and what they do for REQ socket is:

socket.send ("Hello")
message = socket.recv()

.recv() is undefined in zeromq.node and I don't see an alternative for that either. Would you mind pointing me in the right direction?

OK I figured that message event is fired instead.

req_socket.on('message', function (message) {
  console.log('<- ' + message.toString('utf8'));
});

Reopening this because it's HIGHLY inconvenient to work with REQ socket this way. I'll explain why. If you have RPC interface that takes data, performs request and returns response, you have to do some magic dance to funnel received response back to RPC implementation, also you have to take care of execution order, etc. It would be great if there was a way to send request with callback that would be called with response, i.e:

socket.send(req, function (resp) {
   // do something
});

I agree to you, in that it would need extra code/multipart messages to match responses to previous requests in the 'message'-event callback.

Your suggestion looks much better.