java Spring RabbitMQ SimpleRabbitListenerContainerFactory用法
从docs开始,我想通过动态地更改消费者而不重新启动应用程序,使用队列中的消费
我确实看到Spring RabbitMQ的最新版本支持相同的功能,但没有改变相同功能的线索/示例/解释。我看不到正确的源代码,也看不到如何传递参数,比如maxConcurrentConsumers
我正在使用基于XML的Spring RabbitMQ配置和Spring集成
<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" />
有人能指导我如何动态配置消费者吗
# 1 楼答案
首先,你不应该为不同的
<int-amqp:inbound-channel-adapter>
共享相同的rabbitListenerContainerFactory
,因为它们会这样做:所以,只有最后一个适配器获胜。 从另一个角度来看,甚至没有理由有几个适配器。可以为单个适配器指定
queue-names="highLoadQueue,lowLoadQueue"
。 尽管在listener-container
的情况下,您必须在SimpleRabbitListenerContainerFactory
上指定queues
如果您想在运行时更改一些
rabbitListenerContainerFactory
选项,只需将其注入某个服务并调用其setters
如果我错过了什么,请告诉我