2

我想使用消息选择器对 JMS 消息进行负载平衡。

消息具有属性“EntityIX”。

选择器应类似于:

"EntitiyIX Modulus 2 == 0" ==> route to queue A
"EntitiyIX Modulus 2 != 0" ==> route to queue B

在 JMS 消息选择器中计算模数的运算符是什么?

谢谢,亚历克斯

4

4 回答 4

1

根据 API(http://download.oracle.com/javaee/1.4/api/javax/jms/Message.html - 向下滚动到“消息选择器”)没有模运算符。

@Robin 的建议听起来不错。

于 2010-09-24T06:06:10.127 回答
0

In case you want to use more than two consumers try this:

Put a Content Enricher in front of the message consumer. Let the Content Enricher calculate a hash value that is something in the range from zero to one. Choose a simple and predictable hash function. For an order number you could divide the last two digits of the number by 100. Save that hash value at the message, let's say in the property X.

Then you would configure three message consumers with the following message selectors: "X < 1/3", "1/3 <= X and X < 2/3", "2/3 <= X".

If you are allowed to change the message sender, add the property before the message is sent. In this case the content enricher is redundant.

于 2012-11-13T14:52:51.203 回答
0

假设该属性是一个整数,那么我相信你可以做到

  • (EntityIX / 2) = ((EntityIX+1) / 2) -> 路由到 A
  • (EntityIX / 2) != ((EntityIX+1) / 2) -> 路由到 B
于 2010-09-23T16:20:13.480 回答
0

value=2或任何整数

EntityIX-((EntityIX/value)*value)=0-> 通往 A 的路线

EntityIX-((EntityIX/value)*value)<>0-> 通往 B 的路线

于 2018-07-11T07:05:15.217 回答