首页 > 解决方案 > 微服务世界中的 RabbitMQ 交换

问题描述

有没有关于如何在微服务架构中组织 RabbitMQ 交换/队列的最佳实践?

假设我有服务 A、B、C、D。服务 D 需要使用来自 A 和 B 的事件,向 C 发布命令。

我的解决方案 - 每个服务都声明它的交换。交换 A、交换 B、交换 C、交换 D。

客户端可以向该交换发布命令并使用来自这些交换的事件。这些是主题交换,因此对于命令,路由键将是 ServiceA.Command.Command1,对于事件 ServiceA.Event.Event1。

对于我分享的示例:

ServiceD binds queue (with name ServiceD.ServiceA.Event.Queue) to ExchangeA with routing key: ServiceA.Event.#
ServiceD binds queue (with name ServiceD.ServiceB.Event.Queue) to ExchangeB with routing key: ServiceB.Event.#
ServiceD produces command to the exchange ServiceC with routing key ServiceC.Command.Command1

这是正确的方法吗?有什么好的例子我可以看看吗?

标签: rabbitmqmicroservicesamqp

解决方案


Microsoft 示例微服务项目在这里:https ://github.com/dotnet-architecture/eShopOnContainers

通常使用一个 Exchange 和 N 个队列。

交换图像
队列图像


推荐阅读