Pepster
Pepster

Reputation: 2166

How can I declare and subscribe many Queues to an TopicExchange without static config?

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?

Upvotes: 0

Views: 27

Answers (1)

Gary Russell
Gary Russell

Reputation: 174574

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.

Upvotes: 3

Related Questions