Competing Consumer on Redis Pub/Sub supported?

jordan picture jordan · Aug 25, 2011 · Viewed 12.1k times · Source

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

Answer

Tom Clarkson picture Tom Clarkson · Aug 25, 2011

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.