在 RabbitMQ 中通过 属性 或 header 获取消息

Get messages by property or header in RabbitMQ

我是 RabbitMQ 的新手,我遇到了一个问题。我正在尝试通过 API 方法从 queue 获取消息。我已经做到了,如果可能的话,我想通过 header 或 属性 从 queue 获取消息。我阅读了有关 HTTP API 的文档。我还没有找到这样的 API 用于通过某些 header 或属性过滤消息。

我使用那种 API 从 queue 获取消息:

/api/queues/vhost/name/get

并在 body 中:

{"count":20,"ackmode":"ack_requeue_true","encoding":"auto"}

我在想,也许可以通过某种方式在 body 中传递一些过滤器,这样它就可以过滤 return 我想要的消息。

我的消息是这样的:

我试过传入 body type = "myType"header = "myHeader"

I've made that by now I want to get messages from queue by header or property if it is possible.

RabbitMQ 仅按 queue 的顺序传送消息。一旦消息在 queue.

中,就无法过滤

但是,您可以在消息发布到交换器时对其进行过滤。使用 headers 交换并根据 header 值绑定 queues。然后,每个 queue 将包含您期望的消息,然后您可以使用它们。

RabbitMQ 教程中有一节使用 "headers exchange"。以此为指导。

最后,只使用HTTPAPI进行测试。这是一种非常低效的消息检索方式。


注意: RabbitMQ 团队监控 rabbitmq-users mailing list 并且有时只在 Whosebug 上回答问题。