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?

4

1 回答 1

1

首先,您不应该rabbitListenerContainerFactory为不同<int-amqp:inbound-channel-adapter>的 s 共享相同的内容,因为它们会这样做:

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

因此,只有最后一个适配器获胜。另一方面,甚至没有理由拥有多个适配器。您可以queue-names="highLoadQueue,lowLoadQueue"为单个适配器指定。尽管如果listener-container您必须queuesSimpleRabbitListenerContainerFactory.

如果您想rabbitListenerContainerFactory在运行时更改某些选项,只需将其注入某个服务并调用其setters.

如果我错过了什么,请告诉我。

于 2015-04-10T15:31:31.097 回答