【问题标题】:PHP Ampqlib Consumer Dies: Error reading data. Received 0 instead of expected 1 bytesPHP Ampqlib 消费者死机:读取数据时出错。收到 0 而不是预期的 1 个字节
【发布时间】:2015-08-10 15:52:49
【问题描述】:

好的,这是 Symfony2 命令行脚本的一部分。在脚本等待时,它会因这个异常而死。

[PhpAmqpLib\Exception\AMQPRuntimeException]
    Error reading data. Received 0 instead of expected 1 bytes

我搜索了谷歌,发现提到了 heartbeat 和 set_time_out,但是当我尝试在构造函数中设置时,但是当我从默认值更改它时,它死得更快。

这就是我的脚本的设置方式。对于它的 Amqplib 方面。

    // Get the configuration options for RabbitMQ
        $queueConfig = $this->getApplication()->getKernel()->getContainer()->getParameter("rabbit_mq");

    /**
     * Callback function for RabbitMQ
     * Everything in the callback function must remain in the call back function.
     */
    $callback = function($msg)
    {
      $msgObj = json_decode($msg->body, true);
      print_r($msgObj);
    };

    $connection = new AMQPConnection(
        $queueConfig['response']['host'],
        $queueConfig['response']['port'],
        $queueConfig['response']['username'],
        $queueConfig['response']['password'],
        '/'
      );

    $channel = $connection->channel();

    $queueName = 'myQueueName';

    $channel->basic_consume($queueName, '', false, true, false, false, $callback);

    while(count($channel->callbacks)) {
        $channel->wait();
    }

这是来自具有构造函数的 AMQPStreamConnection.php。 AMQPConnection 扩展 AMQPStreamConnection

public function __construct($host, $port,
                            $user, $password,
                            $vhost="/",$insist=false,
                            $login_method="AMQPLAIN",
                            $login_response=null,
                            $locale="en_US",
                            $connection_timeout = 3,
                            $read_write_timeout = 3,
                            $context = null)

关于如何摆脱错误的想法?

【问题讨论】:

    标签: php rabbitmq php-amqplib


    【解决方案1】:

    这个问题的原因是我们使用了亚马逊的负载均衡器,它在某个时间间隔内终止了我们的连接。我所做的是破解了一个while循环以在消费者失败时重新启动它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-21
      • 2012-12-06
      • 1970-01-01
      • 2013-08-29
      • 2014-12-31
      • 1970-01-01
      • 1970-01-01
      • 2015-04-01
      相关资源
      最近更新 更多