JMS - 消息选择器如何与多个队列和主题使用者一起工作? [英] JMS - How do message selectors work with multiple queue and topic consumers?

查看:170
本文介绍了JMS - 消息选择器如何与多个队列和主题使用者一起工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有一个JMS队列,并且多个消费者正在查看队列中的消息。您希望其中一个消费者获得所有特定类型的消息,因此您决定使用消息选择器。

Say you have a JMS queue, and multiple consumers are watching the queue for messages. You want one of the consumers to get all of a particular type of message, so you decide to employ message selectors.

例如,您定义了一个属性,该属性将放入名为的JMS消息头中, targetConsumer 。您应用于消费者的消息选择器 A ,类似于 WHERE targetConsumer ='CONSUMER_A'

For example, you define a property to go in your JMS message header named, targetConsumer. Your message selector, which you apply to the consumer known as, A, is something like WHERE targetConsumer = 'CONSUMER_A'.

很明显,消费者A现在只是抓住具有属性集的消息,就像它在示例中一样。但是,其他消费者是否会意识到这一点? IOW,如果另一个消费者在消费者 A CONSUMER_A 消息C>?我是否需要应用消息选择器,例如 WHERE targetConsumer<> 'CONSUMER_A'给其他人?

It's clear that consumer A will now just grab messages with the property set like it is in in the example. Will the other consumers have awareness of that, though? IOW, will another consumer, unconstrained by a message selector, grab the CONSUMER_A messages, if it looks at the queue before Consumer A? Do I need to apply message selectors like, WHERE targetConsumer <> 'CONSUMER_A' to the others?

我现在正在RTFMing并收集经验数据,但希望有人可能知道他们的头脑。

I am RTFMing and gathering empirical data now, but was hoping someone might know off the top of their head.

推荐答案

当多个消费者使用相同的队列时,需要在这些消费者之间正确配置消息选择器,以便在确定目标消费者。

When multiple consumers use the same queue, message selectors need to configured correctly across these consumers so that there is no conflict in determining the intended consumer.

对于消息驱动bean(JMS消息的使用者),可以在ejb-jar.xml文件中指定选择器从而允许在部署时完成配置(而不是在开发期间指定消息选择器的相反视图)。

In the case of message-driven-beans (a consumer of JMS messages), the selector can be specified in the ejb-jar.xml file thereby allowing for the configuration to be done at deployment time (instead of the opposing view of specifying the message selector during development).

编辑:在现实生活中,当不同的消费者负责处理包含写在同一队列上的相同头(通常由同一生产者生成)的消息时,这将是有意义的。例如,当生产者无法将JMS消息写入两个单独的买卖队列时,可以在交易应用程序中使用消息选择器来区分买入和卖出订单。

Edit: In real life, this would make sense when different consumers are responsible for processing messages containing the same headers (often generated by the same producer) written onto the same queue. For instance, message selectors could be used in a trading application, to differentiate between buy and sell orders, when the producer is incapable of writing the JMS messages onto two separate buy and sell queues.

这篇关于JMS - 消息选择器如何与多个队列和主题使用者一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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