Process Messages Sequentially with competing consumers

允我心安 提交于 2019-12-24 09:12:19

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/40607967/process-messages-sequentially-with-competing-consumers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!