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.

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
    I'd recommend editing the question to avoid being interpreted as a coding assistance request. In my opinion, if you focus on the general pattern of using a message broker for communicating with multiple consumers it might be an ok question. Jun 20, 2021 at 8:16
  • ok, Will remove the code part. Jun 20, 2021 at 9:48

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.