与 JMS 主题的同步行为
我有下面的流程伪代码,它使用队列发送消息,然后同步监听主题。底层 JMS 提供商是 Tibco EMS。
//Send to Queue
Connection connection = createConnection(); // get the JMS connection
Session session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("sample.queue");
MessageProducer messageProducer = session.createProducer(queue);
Message message = createMessage(); //create JMS message
messageProducer.send(message);
现在,我使用创建的相同 session
对象收听主题,并等待直到有响应。
Topic topic = session.createTopic("sample.topic");
MessageConsumer messageConsumer = session.createConsumer(topic);
//wait for the reply.
Message responseMessage = messageConsumer.receive(60000);
if(responseMessage != null) {
System.out.println("Message received..");
}
我面临的问题是消息对象显示为空。我使用 jms 监控工具进行了测试,该主题确实有一些消息,但上面的代码即使在 60 秒后也无法获取它。
知道我在这里缺少什么吗?
I have below pseudo code of flow which uses queue to send the message and then listen to topic synchronously. The underlying JMS provider is Tibco EMS.
//Send to Queue
Connection connection = createConnection(); // get the JMS connection
Session session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("sample.queue");
MessageProducer messageProducer = session.createProducer(queue);
Message message = createMessage(); //create JMS message
messageProducer.send(message);
Now, I listen to a topic using same session
object created and wait till there is a response.
Topic topic = session.createTopic("sample.topic");
MessageConsumer messageConsumer = session.createConsumer(topic);
//wait for the reply.
Message responseMessage = messageConsumer.receive(60000);
if(responseMessage != null) {
System.out.println("Message received..");
}
The problem that I am facing is that the message object is coming out as null. I tested with a jms monitoring tool and the topic does have some message, but the above code is not able to pick it up even after 60 secs.
Any idea what am I missing here ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了。在调用
messageConsumer.receive();
之前,调用connection.start()
以开始传递消息。Figured it out. Just before calling
messageConsumer.receive();
, a call toconnection.start()
to start the delivery of the message.