Does RabbitMQ call the callback function for a consumer when it has some message for it?(RabbitMQ 是否会在有消息时为消费者调用回调函数?)
问题描述
RabbitMQ 是否在有消息时为消费者调用回调函数,或者消费者是否必须轮询 RabbitMQ 客户端?
所以在消费者端,如果有 PHP 脚本,RabbitMQ 可以调用它并将消息/参数传递给它.例如如果在 shard 1 上提交了 rating 并且 aggregateRating 表在 shard 2 上,那么 shard 2 上的 RabbitMQ 消费者会触发脚本 aggRating.php 并传递插入到 shard 1 中的参数吗?
你想要的是 basic.consume
,它允许代理向客户端推送消息.
也就是说,这些库的实现方式不同.它们中的大多数都支持 basic.consume
,但由于所使用框架的固有限制,有些不支持(最值得注意的是许多其他客户端所基于的官方 RabbitMQ C 客户端).
如果您的 PHP 库不支持 basic.consume
,您要么必须使用轮询(不好),要么可以使用更完整的客户端之一来驱动脚本.例如,您可以编写一个从代理消费的 Python 或 Java 程序(因此,代理 推送 向它们传递)并且他们可以在收到新消息时调用脚本.官方教程很好地介绍了 AMQP API,是一个很好的起点.p>
从大多数角度来看,这很有效,但它确实需要与代理的稳定连接.
如果对各种客户端的功能有疑问,或者如果您需要更多指导,RabbitMQ 讨论 邮件列表是提问的好地方.开发人员会重点回答那里发布的任何问题.
Does RabbitMQ call the callback function for a consumer when it has some message for it, or does the consumer have to poll the RabbitMQ client?
So on the consumer side, if there is a PHP script, can RabbitMQ call it and pass the message/parameters to it. e.g. if rating is submitted on shard 1 and the aggregateRating table is on shard 2, then would RabbitMQ consumer on shard 2 trigger the script say aggRating.php and pass the parameters that were inserted in shard 1?
What you want is basic.consume
, which allows the broker to push messages to clients.
That said, the libraries are implemented differently. Most of them have support for basic.consume
, but because of inherent limitations of the frameworks used, some don't (most notably the official RabbitMQ C client on which a lot of other clients are based).
If your PHP library does not support basic.consume
, you either have to use polling (bad), or you could use one of the more complete clients to drive the script. For instance, you could write a Python or Java program that consumes from the broker (so, the broker pushes deliveries to them) and they could call the script whenever a new message is received. The official tutorials are a great introduction to the AMQP APIs and are a good place to start.
This is efficient from most points of view, but it does require a stable connection to the broker.
If in doubt about the capabilities of the various clients, or if you need more guidance, the RabbitMQ Discuss mailing list is a great place to ask questions. The developers make a point of answering any query posted there.
这篇关于RabbitMQ 是否会在有消息时为消费者调用回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:RabbitMQ 是否会在有消息时为消费者调用回调函数?
基础教程推荐
- 在多维数组中查找最大值 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01