<bdo id='yX0d1'></bdo><ul id='yX0d1'></ul>
<legend id='yX0d1'><style id='yX0d1'><dir id='yX0d1'><q id='yX0d1'></q></dir></style></legend>
<tfoot id='yX0d1'></tfoot>
    1. <i id='yX0d1'><tr id='yX0d1'><dt id='yX0d1'><q id='yX0d1'><span id='yX0d1'><b id='yX0d1'><form id='yX0d1'><ins id='yX0d1'></ins><ul id='yX0d1'></ul><sub id='yX0d1'></sub></form><legend id='yX0d1'></legend><bdo id='yX0d1'><pre id='yX0d1'><center id='yX0d1'></center></pre></bdo></b><th id='yX0d1'></th></span></q></dt></tr></i><div id='yX0d1'><tfoot id='yX0d1'></tfoot><dl id='yX0d1'><fieldset id='yX0d1'></fieldset></dl></div>

        <small id='yX0d1'></small><noframes id='yX0d1'>

      1. RabbitMQ 是否会在有消息时为消费者调用回调函数?

        时间:2023-11-30

          <small id='ruVcc'></small><noframes id='ruVcc'>

            <tbody id='ruVcc'></tbody>

            <i id='ruVcc'><tr id='ruVcc'><dt id='ruVcc'><q id='ruVcc'><span id='ruVcc'><b id='ruVcc'><form id='ruVcc'><ins id='ruVcc'></ins><ul id='ruVcc'></ul><sub id='ruVcc'></sub></form><legend id='ruVcc'></legend><bdo id='ruVcc'><pre id='ruVcc'><center id='ruVcc'></center></pre></bdo></b><th id='ruVcc'></th></span></q></dt></tr></i><div id='ruVcc'><tfoot id='ruVcc'></tfoot><dl id='ruVcc'><fieldset id='ruVcc'></fieldset></dl></div>
            <legend id='ruVcc'><style id='ruVcc'><dir id='ruVcc'><q id='ruVcc'></q></dir></style></legend>
              • <bdo id='ruVcc'></bdo><ul id='ruVcc'></ul>

                <tfoot id='ruVcc'></tfoot>
                • 本文介绍了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 是否会在有消息时为消费者调用回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:PHP 守护进程/worker 环境 下一篇:PHP致命错误:找不到类'AMQPConnection'

                  相关文章

                    <bdo id='iBQZW'></bdo><ul id='iBQZW'></ul>

                  1. <small id='iBQZW'></small><noframes id='iBQZW'>

                  2. <i id='iBQZW'><tr id='iBQZW'><dt id='iBQZW'><q id='iBQZW'><span id='iBQZW'><b id='iBQZW'><form id='iBQZW'><ins id='iBQZW'></ins><ul id='iBQZW'></ul><sub id='iBQZW'></sub></form><legend id='iBQZW'></legend><bdo id='iBQZW'><pre id='iBQZW'><center id='iBQZW'></center></pre></bdo></b><th id='iBQZW'></th></span></q></dt></tr></i><div id='iBQZW'><tfoot id='iBQZW'></tfoot><dl id='iBQZW'><fieldset id='iBQZW'></fieldset></dl></div>
                    <tfoot id='iBQZW'></tfoot>

                    1. <legend id='iBQZW'><style id='iBQZW'><dir id='iBQZW'><q id='iBQZW'></q></dir></style></legend>