RabbitMqBundle使用者退出异常"读取数据时出错。收到0而不是预期的1字节"和#34;管道破裂或关闭连接"

时间:2015-12-08 12:56:55

标签: php symfony rabbitmq

以前提出的相同异常消息的问题并没有解决我的问题。

我有一个使用标准bundle cli命令从命令行调用的使用者:

app/console rabbitmq:consumer -m 120 myproject_download

在消耗了一些消息并按预期执行任务后,它将退出并出现以下异常:

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

rabbitmq:consumer [-m|--messages [MESSAGES]] [-r|--route [ROUTE]] [-l|--memory-limit [MEMORY-LIMIT]] [-d|--debug] [-w|--without-signals] [--] <name>

PHP Fatal error:  Uncaught exception 'PhpAmqpLib\Exception\AMQPIOException' with message 'Error reading data. Received 0 instead of expected 7 bytes' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:161
Stack trace:
#0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(147): PhpAmqpLib\Wire\IO\StreamIO->read(7)
#1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(105): PhpAmqpLib\Wire\AMQPReader->rawread(7)
#2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(528): PhpAmqpLib\Wire\AMQPReader->read(7)
#3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(568): PhpAmqpLib\Connection\AbstractConnection->wait_frame(0)
#4 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(214): PhpAmqpLib\Connection\AbstractConnection->wait_channel(1, 0)
#5 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Chan in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 161

Fatal error: Uncaught exception 'PhpAmqpLib\Exception\AMQPIOException' with message 'Error reading data. Received 0 instead of expected 7 bytes' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:161
Stack trace:
#0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(147): PhpAmqpLib\Wire\IO\StreamIO->read(7)
#1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(105): PhpAmqpLib\Wire\AMQPReader->rawread(7)
#2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(528): PhpAmqpLib\Wire\AMQPReader->read(7)
#3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(568): PhpAmqpLib\Connection\AbstractConnection->wait_frame(0)
#4 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(214): PhpAmqpLib\Connection\AbstractConnection->wait_channel(1, 0)
#5 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Chan in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 161

在消费者中,我还向新队列发送消息。使用标准的Symfony依赖注入。如果我省略发送此消息,则会显示以下异常,完全相同:

[PhpAmqpLib\Exception\AMQPRuntimeException]
Broken pipe or closed connection

rabbitmq:consumer [-m|--messages [MESSAGES]] [-r|--route [ROUTE]] [-l|--memory-limit [MEMORY-LIMIT]] [-d|--debug] [-w|--without-signals] [--] <name>

PHP Fatal error:  Uncaught exception 'PhpAmqpLib\Exception\AMQPRuntimeException' with message 'Broken pipe or closed connection' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:190
Stack trace:
#0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(336): PhpAmqpLib\Wire\IO\StreamIO->write('\x01\x00\x01\x00\x00\x00\v\x00\x14\x00(\x00\x00\x00\x00...')
#1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(457): PhpAmqpLib\Connection\AbstractConnection->write('\x01\x00\x01\x00\x00\x00\v\x00\x14\x00(\x00\x00\x00\x00...')
#2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(223): PhpAmqpLib\Connection\AbstractConnection->send_channel_method_frame(1, Array, Object(PhpAmqpLib\Wire\AMQPWriter))
#3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php(170): PhpAmqpLib\Channel\AbstractChannel->send_method_frame(Array, Object(PhpAmqpLib\Wire\A in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 190

Fatal error: Uncaught exception 'PhpAmqpLib\Exception\AMQPRuntimeException' with message 'Broken pipe or closed connection' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:190
Stack trace:
#0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(336): PhpAmqpLib\Wire\IO\StreamIO->write('\x01\x00\x01\x00\x00\x00\v\x00\x14\x00(\x00\x00\x00\x00...')
#1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(457): PhpAmqpLib\Connection\AbstractConnection->write('\x01\x00\x01\x00\x00\x00\v\x00\x14\x00(\x00\x00\x00\x00...')
#2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(223): PhpAmqpLib\Connection\AbstractConnection->send_channel_method_frame(1, Array, Object(PhpAmqpLib\Wire\AMQPWriter))
#3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php(170): PhpAmqpLib\Channel\AbstractChannel->send_method_frame(Array, Object(PhpAmqpLib\Wire\A in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 190

再次启动消费者,具有相同的效果。消耗掉一些消息,然后再次退出。

在php.ini中,max_execution_time和max_input_time比异常发生的时间要高很多。

Symfony config.yml看起来像这样:

# rabbitmq
old_sound_rabbit_mq:
  connections:
    default:
      host:     '192.168.99.100'
      port:     5672
      user:     'guest'
      password: 'guest'
      vhost:    '/'
      lazy:     false
      connection_timeout: 4
      read_write_timeout: 4

      # requires php-amqplib v2.4.1+ and PHP5.4+
      keepalive: false

      # requires php-amqplib v2.4.1+
      heartbeat: 2

发生了什么事?以及如何阻止它退出,直到所有消息都被消费?

1 个答案:

答案 0 :(得分:4)

我刚才遇到了同样的问题

尝试更改:

      connection_timeout: 60
      read_write_timeout: 60

      # requires php-amqplib v2.4.1+ and PHP5.4+
      keepalive: false

      # requires php-amqplib v2.4.1+
      heartbeat: 30

它对我有用。

以下是有关如何使用此值的说明: https://www.rabbitmq.com/heartbeats.html

祝你好运。