JMS:消息选择器中的模运算符

发布于 2024-09-25 03:00:08 字数 252 浏览 0 评论 0原文

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

消息具有属性“EntitiyIX”。

选择器应类似于:

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

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

谢谢, 亚历克斯

I want to load balance JMS messages using message selectors.

A message has a property "EntitiyIX".

The selectors shall be like:

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

What's the operator to calculated the modulus in a JMS message selector?

Thanks,
Alex

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

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

发布评论

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

评论(4

携余温的黄昏 2024-10-02 03:00:08

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

  • (EntityIX / 2) = ((EntityIX+1) / 2) ->到 A 的路线
  • (EntityIX / 2) != ((EntityIX+1) / 2) ->前往 B 的路线

Assuming that the property is an integer, then I believe you could do

  • (EntityIX / 2) = ((EntityIX+1) / 2) -> route to A
  • (EntityIX / 2) != ((EntityIX+1) / 2) -> route to B
涙—继续流 2024-10-02 03:00:08

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

@Robin 的建议听起来很正确。

According to the API (http://download.oracle.com/javaee/1.4/api/javax/jms/Message.html - scroll down to "Message Selectors") there isn't a modulus operator.

What @Robin suggested sounds right.

帅气尐潴 2024-10-02 03:00:08

如果您想使用两个以上的消费者,请尝试以下操作:

放置内容丰富器< /a> 在消息消费者前面。让内容丰富器计算一个范围从 0 到 1 的哈希值。选择一个简单且可预测的哈希函数。对于订单号,您可以将该数字的最后两位除以 100。将该哈希值保存在消息中,假设在属性 X 中。

然后,您可以使用以下消息选择器配置三个消息使用者:“X < 1 /3”,“1/3≤X且X≤2/3”,“2/3≤X”。

如果允许您更改消息发送者,请在发送消息之前添加该属性。在这种情况下,内容丰富器是多余的。

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.

极度宠爱 2024-10-02 03:00:08

value=2 或任意整数

EntityIX-((EntityIX/value)*value)=0 ->路由到 A

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

value=2 or any Integer

EntityIX-((EntityIX/value)*value)=0 -> route to A

EntityIX-((EntityIX/value)*value)<>0 -> route to B

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