- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们有一个用例,即放置一组具有相同 groupId 但 MessageSequenceNumber 不同的消息。这用于对消息进行逻辑排序分组,以便在接收方,接收方可以根据组顺序对所有消息进行分组。我正在关注 IBM MQ v7.5 知识中心页面“Message groups”。
我编写了一段代码来放置消息:-
public boolean writeMessage(String[] messages, String queueName) {
Session session = getQueueConnection().createSession(true,
Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(queueName);
messageProducer = session.createProducer(destination);
for (int i = 0; i < messages.length; i++) {
TextMessage message = session.createTextMessage(messages[i]);
messageProducer.send(message);
}
// Commit the send (Actually put messages to Queue)
session.commit();
return true;
}
现在,我想向数组内的所有消息添加 1 个唯一的 groupID,并添加序列号(msgSeqNum) (1,2,3..)。我如何通过 JMS API 做到这一点?我正在 IBM IIB v8 知识中心页面“Sending messages in a WebSphere MQ message group”上查找 JMS 版本的代码。
最佳答案
David Currie 在 2006 年撰写了一篇不错的 IBM DeveloperWorks 博客,标题为“使用 WebSphere MQ Java 和 JMS API 对消息进行分组”,描述了如何执行您所要求的操作,但该博客最近似乎已被 IBM 删除。
<小时/>Wayback Machine link to "Grouping messages using the WebSphere MQ Java and JMS APIs"
<小时/>下面是David在帖子中提供的信息,看起来放置逻辑比获取逻辑更容易实现。我只在此处包含放置逻辑代码,因为这是您所询问的。我通过电子邮件联系了 David,询问是否会重新发布此博客。
Sending a message group
Let's start by looking at the sending application. As mentioned above,the put message option MQPMO_LOGICAL_ORDER was simply an instructionto the queue manager to automatically allocate message groupidentifiers and sequence numbers. The example in Listing 3 belowdemonstrates how, in the absence of this option in the JMS API, we canset these properties explicitly.
Listing 3. Sending a message group using the WebSphere MQ JMS API
MQConnectionFactory factory = new MQConnectionFactory();
factory.setQueueManager("QM_host")
MQQueue destination = new MQQueue("default");
destination.setTargetClient(JMSC.MQJMS_CLIENT_NONJMS_MQ);
Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(destination);
String groupId = "ID:" + new BigInteger(24 * 8, new Random()).toString(16);
for (int i = 1; i <= 5; i++) {
TextMessage message = session.createTextMessage();
message.setStringProperty("JMSXGroupID", groupId);
message.setIntProperty("JMSXGroupSeq", i);
if (i == 5) {
message.setBooleanProperty("JMS_IBM_Last_Msg_In_Group", true);
}
message.setText("Message " + i);
producer.send(message);
}
connection.close();
关于java - 如何在 Java 中实现 IBM MQ 逻辑排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46242936/
我是一名优秀的程序员,十分优秀!