rabbitmq - 微服务世界中的 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
这是正确的方法吗?有什么好的例子我可以看看吗?
解决方案
Microsoft 示例微服务项目在这里:https ://github.com/dotnet-architecture/eShopOnContainers
通常使用一个 Exchange 和 N 个队列。
推荐阅读
- postgresql - Django 的 IntegerRangeField 和 django-filter 的重叠
- javascript - TypeScript + Babel + Jest 不使用 moduleNameMapper 来减少文件
- php-telegram-bot - 电报机器人 setMyCommands 不工作(PHP)
- c# - 这可以做成一个单一的正则表达式吗?
- javascript - 如何在没有弹出消息的情况下使用 onbeforeunload 事件处理程序?
- python - 对包装自定义 Airflow 插件的函数进行单元测试
- php - 如何在 ci4 路由中传递任意数量的参数?
- php - 在 Telegram 数组中使用 While 循环
- python - /login login() 的 TypeError 缺少 1 个必需的位置参数:“用户”
- javascript - 当前未启用对实验性语法“jsx”的支持