[zeromq-dev] ZMQ_PAIR sockets in 3.x ZMQ / IPC inwinows implementation
Chuck Remes
cremes.devlist at mac.com
Wed Jan 18 16:22:33 CET 2012
On Jan 18, 2012, at 8:58 AM, Dorin Ciobanu (dciobanu) wrote:
> 1. It takes care of packetization (as opposed to a regular TCP socket
> where one has to take care of assembling an entire message before
> feeding it to GBP)
Okay, then you want to stay within the zeromq socket family. That is workable.
> 2. Having a guaranteed 1 to 1 relationship helps on systems where
> multiple users can connect to your TCP ports. For eg. if I open a PUSH
> (tcp) socket, another user (by mistake or on purpose) can pull from the
> same queue and thus breaking my application functionality.
ZMQ_PAIR is the only socket type that *enforces* this, but you can easily use DEALER/ROUTER or DEALER/DEALER to achieve point-to-point communications. You then get all of the zeromq benefits like queueing, auto-reconnect, etc.
The only "price" you pay is that you need to ensure that your code only sets up a single point-to-point link. This is a minor issue that your *code* should already do; if it doesn't then it would be a bug and an easily detectable bug too.
If you are *really concerned* about this possibility, then add a little handshake and/or a heartbeat mechanism to the conversation. You *should* have this anyway even with your current ZMQ_PAIR-based solution. The handshake would only allow the first connector to pass messages. Your code should *log* any other handshake attempts as errors which you can then track down and fix. The heartbeating mechanism would let you timeout your conversation in case there was a communications problem and then allow a socket to connect with the handshake after the timeout expires.
If you need more help on figuring out how this would all work, please ask.
> 3. We've been using ZMQ + GBP in many places in our project, and because
> we now need p1 & p2, PAIR would be [almost] ideal. Otherwise we have to
> add a lot of extra-code to treat non-ZMQ communication separately.
As mentioned above, just use DEALER/ROUTER or DEALER/DEALER. Neither precludes you from using google protocol buffers or any other serialization scheme. All zeromq sockets just pass around binary blobs so it doesn't care what you use for serialization.
cr
More information about the zeromq-dev
mailing list