WebSphere MQ 中的消息组

发布于 2024-12-12 05:15:47 字数 795 浏览 0 评论 0原文

我有一个要求,我需要以属于某个组(设置组 ID)的消息由同一 bean 实例使用的方式处理 JMS 消息(通过 MDB)。我在此需要的行为是按顺序处理具有相同组 ID 的消息(尽管消息顺序无关),并且将它们绑定到相同的 MDB 实例应该可以提供这一点。

这些消息不携带任何类型的序列号(因为它是不相关的),并且我们不知道组中的第一条或最后一条消息是什么(理论上“永远不会”存在组中的最后一条消息)。我们希望消费者能够收到后立即交付。

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 中实现这种行为?

谢谢!

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 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?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凹づ凸ル 2024-12-19 05:15:47

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

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

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

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

//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 为您提供的全部内容。其他任何事情都完全取决于消息传递技术的实现者,该技术是其实现所专有的,而不是可移植代码。

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.

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).

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文