<bdo id='tbzEh'></bdo><ul id='tbzEh'></ul>
  • <tfoot id='tbzEh'></tfoot>

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

        <legend id='tbzEh'><style id='tbzEh'><dir id='tbzEh'><q id='tbzEh'></q></dir></style></legend>
      1. <small id='tbzEh'></small><noframes id='tbzEh'>

        等待一条带有超时的 RabbitMQ 消息

        时间:2023-08-26

        <tfoot id='Ud5vj'></tfoot>
            <tbody id='Ud5vj'></tbody>

            • <small id='Ud5vj'></small><noframes id='Ud5vj'>

              <i id='Ud5vj'><tr id='Ud5vj'><dt id='Ud5vj'><q id='Ud5vj'><span id='Ud5vj'><b id='Ud5vj'><form id='Ud5vj'><ins id='Ud5vj'></ins><ul id='Ud5vj'></ul><sub id='Ud5vj'></sub></form><legend id='Ud5vj'></legend><bdo id='Ud5vj'><pre id='Ud5vj'><center id='Ud5vj'></center></pre></bdo></b><th id='Ud5vj'></th></span></q></dt></tr></i><div id='Ud5vj'><tfoot id='Ud5vj'></tfoot><dl id='Ud5vj'><fieldset id='Ud5vj'></fieldset></dl></div>
                • <bdo id='Ud5vj'></bdo><ul id='Ud5vj'></ul>
                  <legend id='Ud5vj'><style id='Ud5vj'><dir id='Ud5vj'><q id='Ud5vj'></q></dir></style></legend>
                  本文介绍了等待一条带有超时的 RabbitMQ 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想向 RabbitMQ 服务器发送一条消息,然后等待回复消息(在回复"队列上).当然,我不想永远等待,以防处理这些消息的应用程序出现故障 - 需要超时.这听起来像是一项非常基本的任务,但我找不到这样做的方法.我现在遇到了 py-amqplib 和 RabbitMQ .NET 客户端.

                  I'd like to send a message to a RabbitMQ server and then wait for a reply message (on a "reply-to" queue). Of course, I don't want to wait forever in case the application processing these messages is down - there needs to be a timeout. It sounds like a very basic task, yet I can't find a way to do this. I've now run into this problem with both py-amqplib and the RabbitMQ .NET client.

                  到目前为止,我得到的最佳解决方案是使用 basic_get 和中间的 sleep 进行轮询,但这很丑:

                  The best solution I've got so far is to poll using basic_get with sleep in-between, but this is pretty ugly:

                  def _wait_for_message_with_timeout(channel, queue_name, timeout):
                      slept = 0
                      sleep_interval = 0.1
                  
                      while slept < timeout:
                          reply = channel.basic_get(queue_name)
                          if reply is not None:
                              return reply
                  
                          time.sleep(sleep_interval)
                          slept += sleep_interval
                  
                      raise Exception('Timeout (%g seconds) expired while waiting for an MQ response.' % timeout)
                  

                  肯定有更好的方法吗?

                  推荐答案

                  我刚刚在 carrot 中添加了对 amqplib 的超时支持.

                  I just added timeout support for amqplib in carrot.

                  这是 amqplib.client0_8.Connection 的子类:

                  http://github.com/询问/carrot/blob/master/carrot/backends/pyamqplib.py#L19-97

                  wait_multichannel.wait 的一个版本,能够接收任意数字频道.

                  wait_multi is a version of channel.wait able to receive on an arbitrary number of channels.

                  我想这可能会在某个时候在上游合并.

                  I guess this could be merged upstream at some point.

                  这篇关于等待一条带有超时的 RabbitMQ 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 ASP.NET Core 应用程序中设置 RabbitMQ 消费者 下一篇:Rabbitmq Ack 或 Nack,将消息留在队列中

                  相关文章

                  最新文章

                  <tfoot id='MfW5W'></tfoot>

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

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