theMoonlitKnight
theMoonlitKnight

Reputation: 451

ZeroMQ pattern for multiple asynchronous requests to single endpoint

I'm using zmq to develop a distributed application having the following network topology: a client node that initiates a request and a server node that replies to requests. Since the client is a node.js application I can't block after a send call to wait the response, so the scenario is that the client could emit multiple send calls to the same endpoint. On the other side the server is a mobile application that processes one request a time in one thread, blocking if there are not any requests. If this configuration sounds odd, I'm trying to build a sort of RPC initiated by the server to mobile.

I thought to use a DEALER socket client side and a REP socket server side. From zmq guide about DEALER/REP combination:

This gives us an asynchronous client that can talk to multiple REP servers. If we rewrote the "Hello World" client using DEALER, we'd be able to send off any number of "Hello" requests without waiting for replies.

Can it be applied to asynchronous client that can talk to one single server? And could it be a good choice? If not which pattern should I use?

Upvotes: 3

Views: 1313

Answers (1)

Xaqq
Xaqq

Reputation: 4386

Can it be applied to asynchronous client that can talk to one single server? And could it be a good choice?

  1. REQ/REP is not recommended for traffic going over the Internet. The socket can potentially get stuck in a bad state.
  2. The DEALER/REP is for a dealer client talking to multiple REP server. So this does not apply for your use case.

If not which pattern should I use?

In your case it seems to me that using the traditional DEALER/ROUTER is the way to go. What I usually do is prepend my messages by a "tag frame", ie a frame that contain an UUID of some sort that allows me to identifies my request (and their reply) at the application level.

Upvotes: 2

Related Questions