0

I have a Spring-Boot app containing many @Service components for handling event-typed AMQP messages. These messages are published by another component to a single ExchangeTopic separated by routing-keys.

How should I create and subscribe the Queues to the TopicExchange once the application starts and avoid maintaining a massive configuration?

Pepster
  • 1,996
  • 1
  • 24
  • 41

1 Answers1

3

You can simply invoke RabbitAdmin.declareQueue() and declareBinding() as needed.

For each new queue, you can either create a new SimpleMessageListenerContainer or add the queue to an existing container.

Adding queues to a container cancels the existing consumers and immediately creates new ones so there is a (short) interruption.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Would it matter performance wise to create multiple containers (~70)? If creating one container, how would you bind the added queues to the different messagehandlers? – Pepster Jun 18 '16 at 14:38
  • 1
    Probably not a big deal for that number but YMMV. The real gating factor is total message volume. If you need a different handler for each then a container per queue makes most sense. Otherwise you'll need a delegating handler which routes on the received queue. – Gary Russell Jun 18 '16 at 20:16