[英]How to configure and enable a JMS Listener to consume messages based on some condition?
I have two listeners( fooMessages
and barMessages
) in my application, and both of them are connected to same queue.我的应用程序中有两个侦听器( fooMessages
和barMessages
),它们都连接到同一个队列。 At one point of time only one listener will consume the message from the queue based on some condition.在某个时间点,只有一个侦听器会根据某种条件使用队列中的消息。 In application.yml
file if fooEnabled
is set to true
then fooMessages
listener should consume the messages and if fooEnabled
is set to false
then barMessages
listener should consume the messages.在application.yml
文件中,如果fooEnabled
设置为true
,则fooMessages
侦听器应使用消息,如果fooEnabled
设置为false
,则barMessages
侦听器应使用消息。
Listeners:听众:
@JMSListener(destination="${queueName}", selector = "${selectorName}")
public void fooMessages(Message message) {
// foo logic
}
@JMSListener(destination="${queueName}", selector = "${selectorName}")
public void barMessages(Message message) {
// bar logic
}
application.yml
file: application.yml
.yml 文件:
queueName: myqueue
selectorName: "priority=medium"
fooEnable: true
How can I configure the listener to handle this scenario?如何配置侦听器来处理这种情况?
id
给每个听众一个id
JmsListenerEndpointRegistry
bean - registry.getListenerContainer("fooListener").start();
使用JmsListenerEndpointRegistry
bean 手动启动容器 - registry.getListenerContainer("fooListener").start();
@Bean
ApplicationRunner runner(@Value("${fooEnabled}") boolean fooEnabled,
@Value("${barEnabled}") boolean barEnabled, JmsListenerEndpointRegistry registry) {
return args -> {
if (fooEnabled) ...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.