如何通过相关性ID将RabbitMq消息聚合为单个消息 [英] How to aggregate RabbitMq messages into single message by correlation ID

查看:361
本文介绍了如何通过相关性ID将RabbitMq消息聚合为单个消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有一个需要按顺序执行的命令管道,并且其中一些命令包含应并行执行的多个操作(相同的相关ID).并假设我需要知道何时执行所有并行操作,以便进一步在管道中继续执行.

Let's say that I have a pipeline of commands that need to be executed sequentially and that some of the commands contain multiple operations that should be executed in parallel (same correlation id). And let's assume that I need to know when all parallel operations are executed in order to proceed with execution further in the pipeline.

是否可以仅使用RabbitMQ通过使用交换和队列来实现这种编排,而无需使用诸如数据库之类的外部数据源?

Is it possible to achieve this kind of orchestration with RabbitMQ alone by using exchanges and queues without usage of external data sources like database ?

我对以下用例感兴趣: 我刚刚在同一队列中发布了3条相同类型的消息.这些消息正在并行处理.我只想在所有具有相同相关ID的消息成功完成后才发布新消息.

I am interested in the following use case: I have just published 3 messages of the same type on the same queue. Those messages are being processed in parallel. I would like to publish a new message only when all messages of the same correlation ID are finished successfully.

是否可以通过RabbitMQ实现这一目标?

Is there a way to achieve this with RabbitMQ ?

推荐答案

听起来您可以使用分散收集模式.这可以通过图表很好地解释该模式:

It sounds like you could use the scatter-gather pattern. This explains that pattern quite well with a diagram:

http://www.enterpriseintegrationpatterns.com/patterns/messaging/BroadcastAggregate.html

这是有关如何使用RabbitMQ实施的教程: http://geekswithblogs.net/michaelstephenson/archive/2012/08/06/150373.aspx

And here is a tutorial on how to implement with RabbitMQ: http://geekswithblogs.net/michaelstephenson/archive/2012/08/06/150373.aspx

这篇关于如何通过相关性ID将RabbitMq消息聚合为单个消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆