Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Competing Consumer on Redis Pub/Sub supported?

I have 2 services. Both of them need subscribe to the same channel.

The 2 services are load balanced. Each service runs on multiple servers.

So how can I be sure only 1 instance of each service consume the message of that channel.

Is this supported on Redis?

Thanks

like image 661
jordan Avatar asked Aug 25 '11 19:08

jordan


People also ask

Does Redis support pub sub?

Aside from data storage, Redis can be used as a Publisher/Subscriber platform. In this pattern, publishers can issue messages to any number of subscribers on a channel. These messages are fire-and-forget, in that if a message is published and no subscribers exists, the message evaporates and cannot be recovered.

How many subscribers can Redis handle?

Regarding the number of subscribers and publishers, it is limited by the maxclients setting, 10,000 by default. There is no limitation for subscribers and publishers, but the maximum clients (connections) limit applies.

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).

Is Redis pub/sub fast?

Redis Pub/Sub is designed for speed (low latency), but only with low numbers of subscribers —subscribers don't poll and while subscribed/connected are able to receive push notifications very quickly from the Redis broker—in the low ms, even < 1ms as confirmed by this benchmark.


1 Answers

Pubsub doesn't work that way - the message goes to all connected subscribed clients. However, you could set it up so that the channel is a notification of an update to a list. That way all clients will get the message, but only one can take the item from the list with LPOP.

like image 166
Tom Clarkson Avatar answered Oct 02 '22 04:10

Tom Clarkson