简体   繁体   中英

AMQP - connection timed out

I receive an error, when trying to receive answer from RabbitMQ.

2015-07-03 09:31:12 [10.1.101.55][-][-][error][PhpAmqpLib\Exception\AMQPTimeoutException] exception 'PhpAmqpLib\Exception\AMQPTimeoutException' with message 'The connection timed out after 30 sec while awaiting incoming data' in /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php:130
Stack trace:
#0 /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(147): PhpAmqpLib\Wire\AMQPReader->wait()
#1 /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(105): PhpAmqpLib\Wire\AMQPReader->rawread(7)
#2 /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(528): PhpAmqpLib\Wire\AMQPReader->read(7)
#3 /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(568): PhpAmqpLib\Connection\AbstractConnection->wait_frame(30)
#4 /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(198): PhpAmqpLib\Connection\AbstractConnection->wait_channel(1, 30)
#5 /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(332): PhpAmqpLib\Channel\AbstractChannel->next_frame(30)

When I trying to receive answer from my local pc it works, but on production server - not.

Why, and how I can fix it.

Thanks!

The deafult timeouts for Connection , Read and Write is 3s. In the development, your requests process too faster than production, so you can't see this error message in the development.

If you need a greater timeout (as me), you can set it when you create an instance of AMQPStreamConnection :

$connection = new AMQPStreamConnection(
        'localhost',
        5672,
        'guest',
        'guest',
        '/',
        false,
        'AMQPLAIN',
        null,
        'en_US',
        30, //Connection Timeout
        30 // Read/Write Timeout
);

The above code set the Connection , Read and Write timeouts to 30s which is reasonable in my case.

Make sure the correct port is set. Default is 5672 (not 15672 which is web interface).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM