tonyc
tonyc

Reputation: 51

How to make subscribers load balanced with Redis PubSub?

I am using Redis as message broker in pubsub mode. There are only 1 publisher and N subscribers listening to same channel. For the original pubsub mode, these N subscribers will receive "same" message each time. My questions is, is there any mechanism inside Redis or any other ways for these subscribers get different messages for each one ?

Upvotes: 1

Views: 1991

Answers (2)

Muhamad Shafiq
Muhamad Shafiq

Reputation: 1

thanks for the suggestion using RSMQ https://www.npmjs.com/package/rsmq may do the trick. Its correct tonyc. Just now I used it and it seems like can works fine. Replicated nodejs service app able to handle if both receive the message then justonly one service handle the process.

Upvotes: 0

for_stack
for_stack

Reputation: 22981

You have two choices:

  1. Add messages to a Redis list, and multiple consumers use BLPOP and related commands to consume these messages.

  2. Add messages to Redis Stream, and multiple consumers use XREAD and related commands to consume these messages.

Upvotes: 1

Related Questions