来自docs ,我想通过在不重新启动应用程序的情况下动态更改消费者来使用来自队列的消费。
我确实看到 Spring RabbitMQ 最新版本支持相同的,但没有改变相同的线索/示例/解释。我看不到相同的正确源代码或如何传递像 maxConcurrentConsumers
我正在使用 Spring RabbitMQ 的基于 XML 的配置以及 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" />
谁能指导我如何动态配置消费者?
最佳答案
首先你不应该共享相同的rabbitListenerContainerFactory
对于不同的 <int-amqp:inbound-channel-adapter>
s,因为他们这样做:
protected void onInit() {
this.messageListenerContainer.setMessageListener(new ChannelAwareMessageListener() {
因此,只有最后一个适配器获胜。
从另一方面看,甚至没有理由拥有多个适配器。您可以指定 queue-names="highLoadQueue,lowLoadQueue"
对于单个适配器。
尽管在 listener-container
的情况下您必须指定 queues
在 SimpleRabbitListenerContainerFactory
上.
如果你想改变一些rabbitListenerContainerFactory
运行时的选项,你可以将它注入(inject)一些服务并调用它的 setters
.
如果我遗漏了什么,请告诉我。
关于java - Spring RabbitMQ SimpleRabbitListenerContainerFactory 用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29564694/