问题描述
问题:
- 我以特定顺序(FIFO)接收队列中的消息(例如订单)
- 我的竞争对手正在排队
- 为进一步增加复杂性,消费者可能仅根据订单的状态对订单的特定版本感兴趣.(例如,version1,version 2和version5)
- 订单上的订单版本号可用,但不能用于排序,因为我的侦听器可能对所有版本都不感兴趣(消费者可能只对版本1,版本2和版本5感兴趣)
如何确保我按接收者的顺序处理消费者中的消息?
您不能与多个使用者一起使用,至少不能基于JMS.您需要提供逻辑.
我想的所有解决方案都很烂,因为它具有异步集成的美,并试图使其同步.对于每个附加了版本的对象"或消息"或类型",您可以跟踪收到的版本,并尝试保证顺序进行了处理.如果消费者不按顺序接收它们,则消费者可能会停步不前或重新排队该消息,但是任何一种解决方案都会令人生厌.
如果存在一组版本有限的对象,并且您可能多次看到这些对象,则可以使用消息选择器来确保给定的使用者是唯一看到该特定ID消息的人. /p>
如果您的JMS提供程序支持优先级队列,则可以分配不同的优先级,并希望这能以适当的顺序给它们分配优先级,但是即使那样,似乎也存在竞争条件.
同样,我会问一个问题:您使用的是正确的技术吗?
Problem:
- I Receive messages(say orders) on a queue in a particular sequence(FIFO)
- I have competing consumers on the queue
- To further add to the complexity, the consumer might be interested in only specific versions of the order depending on its state.(Say version1,version 2 and version5)
- The order version number is available on the order, but cannot be used for sequencing since my listener might not be interested in all the versions(The consumer might be interested only in versions Say version1,version 2 and version5)
How do i ensure that i process the messages across the consumers in the order i received them?
You can't with multiple consumers, at least not base JMS. You'll need to provide the logic.
The solutions I'm thinking of all suck because it takes the beauty of asynchronous integration and tries to make it synchronous. For each "object" or "message" or "type" which has version attached to it, you could track what versions you've received and try to guarantee that they are processed in order. If a consumer receives them out of order, the consumer could just stop in its track or could re-queue the message, but either solution has some nastiness to it.
If there's a finite set of objects which are versioned, and you're perhaps seeing the objects multiple times, you could use message selectors to ensure that a given consumer is the only one that sees the messages of that particular ID.
If your JMS provider supports prioritized queues, you could assign different priorities and hope that this gives them in the appropriate order, but even that would seem to have a race condition attached to it.
Again I'll ask the question: are you using the right technology?
这篇关于与竞争的消费者顺序处理消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!