Competing Consumer on Redis Pub/Sub supported?

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.

That's a great idea. Could you please explain more detail on "set it up so that the channel is a notification of an update to a list". Thanks – user217428 Aug 26 at 0:01 Just run two commands when you send a message - one RPUSH and one PUBLISH.

When a client receives a message using SUBSCRIBE, have it call LPOP on the list. If LPOP doesn't return anything another worker has already processed the message so it can be ignored. – Tom Clarkson Aug 26 at 0:07 But then the publisher need to know the subscriber and break the observe pattern.E.g.

Now my publisher knows there are 2 services consume the message. So I need send 2 RPUSH to 2 channel. Each channel map to a service.

Not sure if I fully understand your idea? Thanks – user217428 Aug 26 at 0:20 If you don't want to change the publisher, you will need to flag the message status on the subscriber instead - something like SETNX service1receivedmessage1 1 combined with EXPIRE should work - SETNX will return 0 if another instance of the service already set the flag. – Tom Clarkson Aug 26 at 0:29 This is a really smart solution.So subscribers are talking to each other to make sure the service only execute once, although all servers received the message.

Thanks. If Redis can support competing consumer in pub/sub internally, it would be great. – user217428 Aug 26 at 0:55.

Another approach would be to use B*POP from your service instances. If you have lots of clients running B*POP against a list, whenever you LPUSH to it, one of those clients will get the data, but only one.

Both of them need subscribe to the same channel. The 2 services are load balanced. Each service runs on multiple servers.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions