RabbitMQ 用直接交换来模拟主题交换

发布于 10-25 05:53 字数 275 浏览 3 评论 0 原文

有没有办法让我可以直接交换模拟主题交换(我知道可以得到相反的结果:参见此处),但我的用例是,我已经部署了一个包含大量队列的直接交换器,每个队列都有路由键 mykeyprefix.queue_name_here我想要实现的目标是拥有一个单独的队列,来自所有其他队列的所有消息最终都会进入该队列以供将来分析。

Is there a way I can have a direct exchange simulate a topic exchange (I know that the opposite can be obtained: see here), but my use case here is that I already have deployed a direct exchange with lots of queues, each queue having the routing key mykeyprefix.queue_name_here and what I am trying to achieve is to have also a separate queue to which all of the messages from all the other queues end up for future analysis.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒浓于脸红 2024-11-01 05:53:09

我不相信,或者至少不容易相信。直接交换缺少通配符绑定,因此使用直接交换执行此操作的唯一选择是为每个可能的路由键添加重复队列,并将每个新队列绑定到同一个交换。因为有很多队列,所以会很混乱。

鉴于您的要求通过使用主题交换完全满足,我很好奇为什么您不能只使用它。您的生产者不会关心(因为他们只是将消息推送到 Exchange),而您的消费者也不需要更改(因为他们只是从可以绑定到任何类型的 Exchange 的队列中拉取)。至于迁移,您可以将队列绑定到两个 Exchange,然后将它们与旧的直接 Exchange 解除绑定。当您移动所有队列后,您可以删除直接交换,只留下您真正需要的主题交换。

I don't believe so, or at least not easily. Direct exchanges lack wildcard bindings, so the only option you'd have to do this with a direct exchange would be to add a duplicate queue for each of your possible routing keys and bind each of those new queues to the same exchange. Since you have lots of queues that's going to be quite messy.

Given that your requirement is met exactly by using a topic exchange, I'm curious as to why you can't just use that. Your producers won't care (since they just push messages to an Exchange) and your consumers won't need to change (since they just pull from a queue that could be bound to any type of Exchange). As for migration, you can bind the queues to both Exchanges and then unbind them from the old direct exchange. When you get every queue moved over you can then delete the direct exchange, leaving you with only that nice topic exchange that you really need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文