Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis PUB/SUB: how to ignore own messages?

The idea is: I have N WCF services which connected and subscribed to the same Redis message channel. These services use this channel to exchange messages to sync some caches and other data.

How each service can ignore its own messages? I.e. how to publish to all but me?

like image 941
ZedZip Avatar asked Jul 02 '15 08:07

ZedZip


People also ask

Does Redis Pub/Sub store messages?

The pub/sub messages are not queued, and even less persisted. They are only buffered in the socket buffers, and immediately sent to the subscribers in the same event loop iteration as the publication. If a subscriber fails to read a message, this message is lost for the subscriber. You could store them in lists.

Is Redis Pub/Sub blocking?

Redis' pub/sub sends messages to clients subscribed (listening) on a channel. If you are not listening, you will miss the message (hence the blocking call). If you want to have it non-blocking, I recommend using a queue instead (redis is pretty good at that too).

How does Redis Pub/Sub works?

Redis Pub/Sub implements the messaging system where the senders (in redis terminology called publishers) sends the messages while the receivers (subscribers) receive them. The link by which the messages are transferred is called channel. In Redis, a client can subscribe any number of channels.

Is Redis Pub/Sub persistent?

No - Redis' Pub/Sub has no persistence, and once a message has been published, it is sent only to the connected subscribed clients.


1 Answers

It looks like Redis PUB/SUB doesn't support such filtration. So, the solution is to use set of individual channels for every publisher and common channel for subscription synchronization between them. Here is an golang example of no-echo chat application.

like image 128
mangup Avatar answered Sep 25 '22 13:09

mangup