[英]Can I send batched messages through a Websphere MQ Queue using Java JMS?
I'm working in a project that requires to send multiple messages to another application via asynchronous Websphere MQ messages. 我正在一个需要通过异步Websphere MQ消息将多个消息发送到另一个应用程序的项目中。 Actually I'm opening and closing sessions for every message I send. 实际上,我正在为发送的每条消息打开和关闭会话。 I appreciate your answers. 感谢您的回答。 By the way this is my first post here. 顺便说一句,这是我在这里的第一篇文章。
I figure something like this should work: 我认为这样的事情应该工作:
Session session = connection.createSession(false, SESSION.AUTO_ACKNOWLEDGE);
// Create first message
Message msgOne = session.createTextMessage("Message One");
// Set reply-to queue to REPLY1QUEUE
msgOne.setJMSReplyTo(session.createQueue("REPLY1QUEUE"));
// Create another message.
Message msgTwo = session.createTextMessage("Message Two");
msgTwo.setJMSReplyTo(session.createQueue("REPLY2QUEUE"));
// Initialize destination queue and message producer.
MessageProducer producer = session.createProducer(session.createQueue("DESTQUEUE"));
// Connect, send and close.
connection.start();
producer.send(msgOne);
producer.send(msgTwo);
connection.close();
// Close the session.
session.close();
If I'm not mistaken, the reply-to queue is optional. 如果我没记错的话,回复队列是可选的。
In your question header, you mentioned the word batched which made me think you might want to send all the grouped messages in a single transaction so that all messages in the group are delivered or none at all. 在您的问题标题中,您提到了批处理一词,这使我认为您可能希望在单个事务中发送所有分组的消息,以便使组中的所有消息都传递或根本不传递。 (An atomic send). (原子发送)。 If this is an important piece, I would slightly modify Friek's (clean and concise) code as follows: 如果这很重要,我将对Friek(简洁明了)的代码进行如下修改:
Session session = connection.createSession(true, SESSION_TRANSACTED);
....
producer.send(msgOne);
producer.send(msgTwo);
session.commit();
....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.