2

From the docs, I want to use consume from queues by dynamically changing the consumers without restarting the application.

I do see that Spring RabbitMQ latest version supports the same, but no clue/example/explanation to change the same. I couldn't see proper source code for the same or how to pass params like maxConcurrentConsumers

I am using XML based configuration of Spring RabbitMQ along with Spring integration

<bean id="rabbitListenerContainerFactory"
      class="org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory">
    <property name="connectionFactory" ref="rabbitConnectionFactory"/>
    <property name="concurrentConsumers" value="3"/>
    <property name="maxConcurrentConsumers" value="10"/>
    <property name="acknowledgeMode" value="AUTO" />
</bean>

<int-amqp:inbound-channel-adapter channel="lowInboundChannel" queue-names="lowLoadQueue" advice-chain="retryInterceptor" acknowledge-mode="AUTO" listener-container="rabbitListenerContainerFactory" />
<int-amqp:inbound-channel-adapter channel="highInboundChannel" queue-names="highLoadQueue" advice-chain="retryInterceptor" acknowledge-mode="AUTO" listener-container="rabbitListenerContainerFactory" />

Can anyone guide me how to dynamically configure the consumers?

RaceBase
  • 18,428
  • 47
  • 141
  • 202

1 Answers1

1

First of all you shouldn't share the same rabbitListenerContainerFactory for different <int-amqp:inbound-channel-adapter>s, because they do this:

protected void onInit() {
    this.messageListenerContainer.setMessageListener(new ChannelAwareMessageListener() { 

So, only last adapter wins. From other side there is even no reason to have several adapters. You can specify queue-names="highLoadQueue,lowLoadQueue" for a single adapter. Although in case of listener-container you must specify queues on the SimpleRabbitListenerContainerFactory.

If you want to change some rabbitListenerContainerFactory options at runtime, you can just inject it to some service and invoke its setters.

Let me know if I have missed anything.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • sorry for late reply. so you are saying single adapter for different `queues`. Each queue will have it's own (different) payload. Why should we combine into single adapter? so do we need to have multiple listenerContainerFactory for each `queue`? Why it's named as `Factory`, I thought it's single connection point to listen to multiple queues!! – RaceBase Apr 14 '15 at 09:28
  • Oh! Sorry, I really have missed that part. No, you can't use `SimpleRabbitListenerContainerFactory` for the ``. Its goal for the Annotation `@RabbitListener` configuration. For the XML config you should use `SimpleMessageListenerContainer` bean definition. And yes: separate bean for each ``. Or just rely on the default container from the `` – Artem Bilan Apr 14 '15 at 10:16
  • I couldn't figure out the way still how to change dynamically the consumers. Can you please give me sample example/code/xml config? – RaceBase Apr 16 '15 at 04:51