且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Java中的IBM MQ中实现逻辑排序?

更新时间:2023-09-23 09:33:34

David Currie在2006年撰写了一篇不错的IBM developerWorks博客,标题为使用WebSphere MQ Java和JMS API对消息进行分组",该博客描述了如何执行操作.问,但是看来这是最近被IBM删除的.

There was a good IBM developerWorks blog written by David Currie in 2006 titled "Grouping messages using the WebSphere MQ Java and JMS APIs" that described how to do what you are asking, however it appears this was recently removed by IBM.

我能够通过Google的缓存副本进行查看.以下是David在帖子中提供的信息,看来推杆逻辑比起取逻辑要容易得多.我只在此处包括放置逻辑代码,因为这是您要查询的内容.我通过电子邮件与David联系,询问是否将重新发布此博客.

I was able to view it via Google's cached copy. Below is the information that was provided by David in the post, it appears the putting logic is much simpler to implement compared to the getting logic. I am only including the putting logic code here since this is what you inquired about. I reached out to David via email to ask if this blog will be republished.

发送消息组

让我们先查看发送应用程序.正如刚才提到的, 放置消息选项MQPMO_LOGICAL_ORDER只是一条指令 到队列管理器以自动分配消息组 标识符和序列号.下面清单3中的示例 演示了在JMS API中缺少此选项的情况下,我们如何可以 显式设置这些属性.

Let's start by looking at the sending application. As mentioned above, the put message option MQPMO_LOGICAL_ORDER was simply an instruction to the queue manager to automatically allocate message group identifiers and sequence numbers. The example in Listing 3 below demonstrates how, in the absence of this option in the JMS API, we can set these properties explicitly.

清单3.使用WebSphere MQ JMS API发送消息组

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();