[zeromq-dev] Delivering private messages to subscribed clients

Colgate, Gil gcolgate at ea.com
Sat Aug 6 02:04:50 CEST 2011


It seems like the open source chat servers I've seen open up a connection, 1 for each client.

Messages that come from a client go to the server and are routed to the appropriate end connections . They may be routed in a broadcast to many, or to a few, or to one, or dropped on the floor, or saved in a file for delivery later when the individual comes online.

The message that comes from a client is decorated with the  routing information, a From, a To, a Body. Just like an email.

Private messages, broadcast messages, multi-user chat messages, etc,  all these sorts of messages are just handled differently on the routing layer, not on the connection layer. The decoration on the chat message lets the server decide how to relay the message.

Subscribing to groups, etc, presence information, is handled the same way, as decorated chat messages.

Thus your private message and broadcast message topology is the same in these source code bases.

Just FYI.


From: zeromq-dev-bounces at mail.imatix.com [mailto:zeromq-dev-bounces at mail.imatix.com] On Behalf Of Aja Walker
Sent: Friday, August 05, 2011 3:24 PM
To: zeromq-dev at lists.zeromq.org
Subject: [zeromq-dev] Delivering private messages to subscribed clients

I recently discovered 0MQ and for the last week or so have been in a fog of buzzing possibilities.  I find myself lying awake at night and redesigning old applications within this new paradigm.  Complex apps are re-written so simply and elegantly that the entire program fits in my head.

Still, I am very new to this way of thinking and designing, and so the kinds of solutions that would be apparent to a veteran are not so obvious to me.  One scenario in particular has been bothering me because it seems simple enough but I can't come up with a satisfying solution.  I was hoping someone might help bring me some peace and perhaps a solid night's sleep.

Imagine a simple chat server.  Clients publish messages to the server and the server republishes those messages to all connected clients.  The server has a request-reply port for clients to get a snapshot of all the clients currently online, and also a port publishing client connects and disconnects as they happen.  This is all very straightforward and matches nicely with the 0MQ constructs.

However, we now want to add private messaging capabilities.  The send side would be simple enough: the server would have an additional port to which clients publish private messages along with the name of the client to whom those messages should be delivered.  The question, then, is how to deliver those private messages to the appropriate clients.

1) We could have a private message subscription port, and each client simply filters for private messages to him/her.  But a naughty client could subscribe with no filter and see the private messages of all the clients.

2) We could have the private message port be request-reply, and each client continually makes requests for any queued private messages.  Usually they will get a "none at this time" reply and will have to immediately issue a new request.  This would be a waste of bandwidth.  Perhaps there is some way to do asynchronous request-reply, such that the client sends the request, but instead of blocking while waiting for the reply it can carry on until the reply is ready?  Of course why do we need the request at all?  Let's just use whatever mechanism the reply is using.

3) We could make clients negotiate with the server to open a port just for them through which the private messages could be published.  But it doesn't seem very scalable to open a new port on the server for each client.  (We're assuming the server can't connect to the client since the client may be behind a firewall.)

4) The guide discusses the concept of socket identities and how REP, DEALER, and ROUTER use them to get replies back to the right place, but also warns sternly against using these sockets in ways other than their intended use.  Is there a safe way to use socket identity to asynchronously publish a private message to a specific client?

It seems to me that there must be an elegant solution, but that I am just too ignorant of the subtleties and power of 0MQ to be able to see it.  So, veterans, what's the answer?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110805/b64991fe/attachment.htm>


More information about the zeromq-dev mailing list