使用 HornetQ 强制消息顺序
我已经设置了一个 jms 服务器,其中 HornetQ 作为 JMS 提供者(队列)。
我有一个应用程序充当生产者,另一个应用程序(不同的计算机)充当消费者。
我知道 JMS 规范不能保证传递的顺序,但我正在寻找一种方法来做到这一点:完全按照消息发送的顺序接收消息,即使它是特定于提供商。
有什么想法吗?
I've setup a jms server with HornetQ as a JMS provider (Queue).
I have an application which acts as a producer and another one (different computer) as a consumer.
I understand that the JMS specification doesn't guarantee the order of delivery, but I'm looking for a way to do just that: receive the messages exactly in the order they have been sent, even if it's provider specific.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,这可以通过禁用消费者缓存来实现。这是通过更改
hornetq-jms.xml
来完成的:Apparently this can be achieved by disabling the consumer cache. This is done by changing the
hornetq-jms.xml
:实际上,JMS 规范的第 4.4.10.2 节(消息发送顺序)对于顺序非常清楚。
如果队列或主题订阅有单个生产者和单个消费者,则即使存在重新传递,也始终保证消息排序。
如果您有多个消费者,则在回滚或关闭消费者的情况下可能会重新交付客户端缓冲,并且可能会无序交付客户端缓冲区。
在 HornetQ 上,您还拥有消息组,它对生成的消息赋予额外的排序约束。
Actually section 4.4.10.2 (Order of Message Sends) of the JMS specification is pretty clear about ordering.
If you have a single producer, and single consumer to a queue or topic subscription, message ordering is always guaranteed even in the presence of redeliveries.
If you have multiple consumers, the client buffering may be redelivered in case of rollbacks or closing your consumer, and the client buffer may be delivered out of ordering.
On HornetQ you also have the message group which entitles extra ordering constraints to the produced messages.