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

查看:16
本文介绍了如何通过相关 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 ?

推荐答案

听起来你可以使用 scatter-gather 模式.这用图表很好地解释了这种模式:

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天全站免登陆