dtdb99743 2018-04-17 15:36
浏览 479

使用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(
        $host,
        $port,
        $user,
        $password,
        $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(
    $host, 
    $port, 
    $user, 
    $password
);

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

print "declaring queue: " . time() . "<br>";
$this->m_channel->queue_declare(
    $queueName,
    $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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘