WebSphere MQ中的消息组 [英] Message Groups in WebSphere MQ

查看:124
本文介绍了WebSphere MQ中的消息组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要求我需要处理JMS消息(通过MDB),使得属于某个组(设置了组ID)的消息被同一个bean实例使用。我需要的行为是,具有相同组ID的消息将按顺序处理(尽管消息排序无关紧要),并将它们绑定到同一个MDB实例应该提供。

I have a requirement that I need to process JMS Messages (via MDB) in a way that Messages belonging to a certain group (a group ID is set) are consumed by the same bean instance. The behaviour I require in this is that Messages with the same group ID are processed sequentially (though message ordering is irrelevant), and tying them to the same MDB-instance should provide that.

消息没有携带任何类型的序列号(因为它是无关紧要的),我们不知道组中的第一个或最后一个消息是什么(理论上永远不会是组中的最后一条消息)。我们希望消费者能够在收到消息后立即将其发送。

The messages do not carry any kind of sequence number (as it is irrelevant) and we do not know what the first or last message in a group is (there could theoratically "never" be a last message in a group). We want them to be delivered as soon as the consumer is able to receive them.

ActiveMQ提供了这一功能( http://activemq.apache.org/message-groups.html )只需设置JMSXGroupID即可。但是,我们必须使用WebSphere MQ。到目前为止我发现的是,有可能收集队列中同一组的消息,并使用MessageSelector接收组中的最后消息消息,如 http://www.ibm.com/developerworks/websphere/library/techarticles/0602_currie/0602_currie.html 。我们更喜欢更清洁的方式(比如在ActiveMQ中)。有谁知道如何在WebSphere中实现这种行为?

ActiveMQ provides this exact feature (http://activemq.apache.org/message-groups.html) by simply setting JMSXGroupID. We are bound to WebSphere MQ, though. All I've found out so far is that it is possible to collect Messages of the same group in the queue and using a MessageSelector to receive a "Last Message in Group" Message as described in http://www.ibm.com/developerworks/websphere/library/techarticles/0602_currie/0602_currie.html. We would prefer a cleaner way though (like in ActiveMQ). Does anyone know how to achieve that behaviour in WebSphere?

谢谢!

推荐答案

通常,您在JMS的IBM产品实现中使用MessageSelectors(WebSphere MQ和SIBus实现)。这些相当于一个过滤器,它会扫描基于Web协议的HTTP或SOAP消息的标头。

Generally you use MessageSelectors in IBM product implementations of JMS (both WebSphere MQ and SIBus implementations). These are the equivalent of a filter that would scan the header of an HTTP or SOAP message for web-based protocols.

虽然它可能不是你想要的,但它实际上是是一个干净且经过深思熟虑的设计。

Though it may not be what you want, it actually is a clean and well thought through design.

但是,如果你不想使用MessageSelectors,你可能需要自己构建并处理一条消息。扫描标题的前端MDB,然后将消息转发到适当的队列,其中只有关心分组消息的MDB将处理它们(类似于网关/消息选择器模式)。

However, if you do not want to use MessageSelectors, you will probably have to build your own and "process" a message with a fronting MDB that scans the headers, and then forwards the message to an appropriate queue, where only the MDB that cares about the grouped messages will process them (sort of a gateway/message selector pattern).

如果您正在使用纯JMS API,那么您可以要求Session对象创建一个MessageConsumer,其中包含您要过滤的指定选择器字符串(标题中的值)(同样,您必须自己设置)。

If you are using the "pure" JMS API's, then you can ask the Session object to create a MessageConsumer with the specified selector string (value in the header) you want to filter on (again you have to set this yourself).

//assume we have created a JMS Connection and Session object already.
//and looked up the Queue we want already.
MessageConsumer consumerWithSelector = session.createConsumer(queue, groupId);

这是纯粹的JMS API给你的。其他任何事情完全取决于消息传递技术的实现者,然后它们的实现是专有的,而不是可移植的代码。

This is all the pure JMS API's give you. Anything else is purely up to the implementer of the messaging technology, which is then proprietary to their implementation and not portable code.

这篇关于WebSphere MQ中的消息组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆