2018-04-17 15:36

使用AMQplib的RabbitMQ - queue_declare的超时

I use RabbitMQ for handling logging between services (written in PHP). If services can't connect to RabbitMQ, they timeout within 3 seconds and try to use a different method for logging. This has been tested and works well with if the RabbitMQ server is down, or behind a firewall. The code that has these timeouts appears to be the in the AMQPStreamConnection class of the php-amqplib/php-amqplib PHP package as shown below:

public function __construct(
        $vhost = '/',
        $insist = false,
        $login_method = 'AMQPLAIN',
        $login_response = null,
        $locale = 'en_US',
        $connection_timeout = 3.0, // here
        $read_write_timeout = 3.0, // and here
        $context = null,
        $keepalive = false,
        $heartbeat = 0
    ) {
        $io = new StreamIO(

Unfortunately, these timeouts don't seem to help me if I am running a massive "Purge queue" operation by clicking the button in the web UI (a queue with over 20 million in size). I wrote some code to log the times during a purge to see what was going wrong:

$this->m_queueName = $queueName;

print "creating connecton: " . time() . "<br>";
$connection = new \PhpAmqpLib\Connection\AMQPStreamConnection(

print "creating channel: " . time() . "<br>";
$this->m_channel = $connection->channel();

print "declaring queue: " . time() . "<br>";
    $passive = false,
    $durable = true,
    $exclusive = false,
    $auto_delete = false,
    $nowait = false,
    $arguments = null,
    $ticket = null

print "queue declared. " . time() . "<br>";

The result being as follows:

creating connecton: 1523977606
creating channel: 1523977606
declaring queue: 1523977606
queue declared. 1523977622
hello world: 1523977622 

I can see that the connection and channel get created, but the declaration of the queue takes way too long to respond and I would rather the queue_declare step would timeout in 3 seconds and an Exception be thrown. Is this possible? What configuration variable(s) do I need to change?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答