【发布时间】:2014-05-18 08:16:00
【问题描述】:
我的 JMS 消费者白天在 JMS 队列上产生任意数量(比如 n)条消息。首先我在评估消息的同步处理
说在 23.0 时钟,现在我想消费所有消息。这是主要方法
以下是按顺序(非同时)执行的方法:-
我是否需要在单个消费者上调用 consumer.receive() 方法 n 次(直到返回 consumer.receive() return null )?
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue("TEST.FOO");
// Create a MessageConsumer from the Session to the Topic or Queue
MessageConsumer consumer = session.createConsumer(destination);
// Wait for a message
Message message = consumer.receive();
如何同时处理 :- 我想同时处理 20 条消息
我是否需要创建 20 个线程,每个线程创建自己的消费者并接收消息?
【问题讨论】:
-
您尝试过自己的建议吗?
-
@Simon 第一个我试过但关于第二个我不确定它是否正确?