有没有办法验证RabbitMQ的路由密钥格式或消息模式?

发布于 2025-02-04 15:07:49 字数 254 浏览 2 评论 0原文

我正在使用RabbitMQ作为消息经纪人。我有一个API,可以接受另一个过程中的消息,并使用Python Pika库将消息发送到RabbitMQ。我想验证两件事:

  1. 路由键的格式是预期的格式(例如,我们希望路由键是< data-; data-type>。。成功|失败>
  2. 消息遵循消费者期望的JSON架构。

我知道我可以在API级别上进行验证路由键,如果此验证在Pika库中可行。

I am using RabbitMQ as a message broker. I have an An API that accepts the message from another process and uses the python pika library to send the message to RabbitMQ. I want to validate two things:

  1. The format of the routing key is in an expected format (for example, we expect the routing key to be something like <data-type>.<update-stage>.<success|failure>
  2. The message follows the json schema expected by the consumers.

I know that I can easily do the validation at the API level, but I was wondering if RabbitMQ itself has any way to register schemas or validate the format of the routing key, and if this validation is doable within the pika library.

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

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

发布评论

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

评论(1

梦在深巷 2025-02-11 15:07:49

我想知道RabbitMQ本身是否可以注册模式或验证路由密钥的格式,以及Pika Library中是否可行此验证

No中可行的验证,这是不受欢迎的。

您应该能够通过自定义的RabbitMQ插件来完成它。您可以使用 Message timestamp插件作为指导。

实际上,这是一个足够有趣的问题,我会试一试。订阅此存储库 -

https://github.com/lukebakken/lukebbitmq-message-message-validator

我在那里导入了消息时间戳插件代码,并将其迁移到验证器。

请在此处打开一个GitHub问题以自我介绍,我将为您的存储库添加您作为合作者。

I was wondering if RabbitMQ itself has any way to register schemas or validate the format of the routing key, and if this validation is doable within the pika library

No, this is not supported out-of-the box.

You should be able to accomplish it via a custom RabbitMQ plugin. You could use the Message Timestamp plugin as a guide.

In fact, this is an interesting enough problem I will give it a shot. Subscribe to this repository -

https://github.com/lukebakken/rabbitmq-message-validator

I have imported the message timestamp plugin code there and will migrate it to a validator.

Please open a GitHub issue there to introduce yourself and I will add you as a collaborator to my repository.

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