同时从单个队列处理两个或多个相同的JMS消息

huangapple 未分类评论47阅读模式
标题翻译

Processing of two or more same JMS messages concurrently from a single queue

问题

考虑以下场景:

应用程序 - MessageReaderApplication(Spring Boot 应用程序)
部署在 - PaaS_node_1 和 PaaS_node_2
队列管理器 - QM
队列 - QM_QUEUE
并发度 - 2

MessageReaderApplication 从 QM_QUEUE 中读取消息,并根据消息中的 client_number 进行处理(client_number 是消息的唯一属性)。对于两条独立的消息(不同的 client_number),应用程序表现良好,因为一条消息的处理与其他消息无关。

问题出现在当相同的客户(相同的 client_number)的消息在队列中同时出现两次时。在这种情况下,理想的做法是先处理第一条消息,然后再处理第二条消息。但在这里,我们无法预测消息的执行顺序。假设 PaaS_node_1 拾取了第一条消息并开始处理,与此同时,PaaS_node_2 拾取了第二条消息并在 PaaS_node_1 处理第一条消息之前完成了处理。

我们如何在 JMS 消息传递中实现这种类型的并发控制?

英文翻译

Consider below scenario:

Application - MessageReaderApplication (Spring Boot Application)
Deployed in - PaaS_node_1 and PaaS_node_2 
Queue Manager - QM
Queue - QM_QUEUE
Concurrency - 2

MessageReaderApplication reads messages from QM_QUEUE and processes them according to client_number in the message (client_number is a unique attribute of the message). The application behaves well for two independent messages (different client_number) as the processing of one message is independent of others.

The problem comes when the messages come for the same client (same client_number) twice at the same time in the queue. In this case, the desirable action is to process the first message prior to the second one. But here we cannot predict the execution order of the messages. Suppose PaaS_node_1 picked the first message and started processing on it meanwhile the second message picked by PaaS_node_2 and finished processing before processing the first message by PaaS_node_1.

How can we achieve this kind of concurrency control in JMS messaging?

答案1

得分: 0

你可以为每个 clientId 单独设置一个队列,或者为每个客户端 id 设置一个独立的监听器(使用消息选择器仅获取那些消息)。

英文翻译

You either need a separate queue for each clientId or a separate listener for each client id (using a message selector to only get those messages).

huangapple
  • 本文由 发表于 2020年3月17日 02:38:40
  • 转载请务必保留本文链接:https://java.coder-hub.com/60711517.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定