OK this is part of a Symfony2 Commandline script. While the script is waiting it dies with this Exception.
[PhpAmqpLib\Exception\AMQPRuntimeException]
Error reading data. Received 0 instead of expected 1 bytes
I have searched google and found mention of heartbeat and set_time_out, but when I have tried to set in the constructor, but instead when I change it from the defaults it dies faster.
This is how my script is setup. for the Amqplib aspect of it.
// 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();
}
This is from AMQPStreamConnection.php which has the constructor. AMQPConnection extends 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)
Thoughts on how to get rid of the error?
The reason for this issue was that we were using Amazon's load balancer and it was killing our connection at a certain time interval. What I did was hacked a while loop to restart the consumer when it failed.