如何同时处理异步jms队列消息? [英] How to concurrently process the asynchronous jms queue message?

查看:143
本文介绍了如何同时处理异步jms队列消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JMS使用者白天会在JMS队列上产生任意数量的消息.尽快 消息到达后,将转到消息侦听器.如果介于两者之间,但我需要其他消息,它会转到另一个消息侦听器,而不等待第一个消息?

My JMS consumer produces any number of messages on a JMS queue during the day. As soon as a message arrives it goes to message listener. If in between I need some other message comes, it goes to another message listener does not wait for first one?

根据我的理解,我需要创建两个使用者(假设我要同时处理2条消息),每个使用者都有自己的会话.两个使用者都可以使用相同的消息侦听器.正确的?

As per my understanding here I need to create two consumer(assume i want to process 2 message concurrently) each having its own session. Both consumer can use the same message listener. Right?

我不确定是否可以通过单个用户实现它,但是可以使用多个听众吗?

I am not sure if I can achieve it with single consumer but can I with multiple listeners?

类似这样的内容单个队列:与多个使用者进行并发消息处理

推荐答案

每个 JMS文档 @bgth引用,单个会话中的多个MessageListener将无法提供并发性:

Per the JMS documentation @bgth cites, multiple MessageListeners in a single session will not provide concurrency:

用于创建消息使用者的会话会序列化向该会话注册的所有消息侦听器的执行.在任何时候,该会话的消息侦听器中只有一个正在运行"

"The session used to create the message consumer serializes the execution of all message listeners registered with the session. At any time, only one of the session’s message listeners is running"

为了并发,您需要在单独的线程中进行多个会话和多个使用者.在这种情况下,您可以重用相同的MessageListener,但是它必须是线程安全的.

For concurrency, you need multiple sessions and multiple consumers in separate threads. You can reuse the same MessageListener in this case, but it must be threadsafe.

这篇关于如何同时处理异步jms队列消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆