1

I have a scenario where I have to route a list of messages that I get to respective users. For suppose if I have

messages = [
  { text: 'hi', user_id: 1 },
  { text: 'hi', user_id: 2 },
  { text: 'hi', user_id: 3 },
  { text: 'hi', user_id: 4 },
  { text: 'hi', user_id: 5 },
];

I read in a blog where creating queues dynamically is an antipattern. https://derickbailey.com/2015/09/02/rabbitmq-best-practices-for-designing-exchanges-queues-and-bindings/

I also tried creating queues on the producer side, this is creating queues, but could not consume messages from that queues as I dont the name of the queues when consuming it.

How can I handle this case in an efficient manner?

1 Answers1

2

First of all, it's normal that each user has their own queue. I don't know why the blog author recommends against it (didn't read) but I assume that his case is a bit different from yours.

Depending on your real needs (i.e. do you create a messaging app, part of a game, etc.) you might need to build something on top of RabbitMQ,

In general, topic or header routing in the respective exchange types is preferable to direct routing for messages that are intended for multiple users. For example, you might have topics such as channel.support, channel.developers and channel.alien-sightings that users can subscribe to.

For messages intended for a single consumer, you need to detail your requirements. Do you need persistent queues per user? Do you need to support one user having multiple devices getting the same messages? The actual solution would depend on the requirements, and it might involve some permission juggling if you want to ensure privacy.