Competing Consumer on Redis Pub/Sub supported?

你。 提交于 2019-12-17 23:26:44

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/7196306/competing-consumer-on-redis-pub-sub-supported

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!