PHP Ampqlib Consumer Dies:读取数据时出错。收到 0 而不是预期的 1 个字节

PHP Ampqlib Consumer Dies: Error reading data. Received 0 instead of expected 1 bytes

好的,这是 Symfony2 命令行脚本的一部分。当脚本等待时,它会死于此异常。

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

我搜索了 google 并发现了 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)

关于如何消除错误的想法?

出现此问题的原因是我们使用了 Amazon 的负载均衡器,它会在特定时间间隔终止我们的连接。我所做的是破解一个 while 循环以在失败时重新启动消费者。