spring boot – RabbitMQ – creating dynamic queues with a listener per queue

Based on this information I read about dynamically creating queues in an RabbitMQ environement. The info is duplicated a lot over the internet, so I guess it is a good starting point. 😉

The use case is that over time I need a dynamic queues with listeners attached to it. Queues come and go. There will be about 100 queues/listeners. After a lot of investigion this seems the right way to go.

While experimenting a lot with this code from the article, I guess the ‘exchangeName’ is attached to a listener(Id). I expected it to be a bindingKeyname (or routingKey). Anyway, an AbstractMessageListenerContainer is attached to an exchangeName. Does this mean that one ListenerContainer is handling a series of attached queues? I was not able to get a listener attached to it.

I saw also solutions using an @JmsListener or @RabbitListener annotation. But in that case I guess I cannot create those listeners dynamically, even with SPEL notation.

So, how can I dynamically create a queue for 1 exchangeName but with different bindingKeys (aka routingKeys)? When reading a lot about this, I guess a prototype-bean must be the best solution. Then I could attach a listener method (onMessage) to it. But I haven’t been able to find a good solution yet. So, any good suggestion would really help.

It doesn’t matter for me to use a proto-bean or just a POJO. Whatever is more easy and light-weight.

Read more here: Source link