Question

Approach

I'm building an asynchronous IM/chat application with ZeroMq, just as a learning exercise, using the following approach.

The server uses two ROUTER sockets, similar to lbbroker.java, reading from incoming and writing to outgoing, while manipulating the envelope for delivery to the intended receiver.

Clients set a unique identity with socket.setIdentity(), and use PULL and PUSH sockets, instead of REQ/REP, for sending and receiving chat messages asynchronously. I've built and tested the code, everything appears to work fine.

Async Chat

Questions

  • Is the use of PUSH/PULL with ROUTER a valid approach?

  • Why do chat clients become unreachable when dropping off then reconnecting?

Sally becomes unreachable if she disconnects then reconnects, she can no longer receives chat messages. After debugging the server, I confirmed it's definitely sending messages with the correct envelope to sally. I also used outgoing.setRouterMandatory(true) to ensure unaddressable messages weren't being dropped by the server, but no errors got raised.

Was it helpful?

Solution

After further research, while PUSH and PULL sockets work with ROUTER, they are not valid socket combinations as per the ZeroMq spec.

A DEALER socket on the client side is a better approach. DEALER supports bidirectional message transfer, basically doing the job of PUSH and PULL but with a single socket.

I started a thread on Github discussing the issue, it includes some sample code for agent-based pattern using DEALER.

https://github.com/zeromq/jeromq/issues/81

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top