rabbitmq php basic_consume 怎么在没有消息接收的时候退出脚本

require_once __DIR__ . '/vendor/autoload.php';  
    use PhpAmqpLib\Connection\AMQPStreamConnection;  
    $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');  
    $channel = $connection->channel();  
      
    $channel->queue_declare('hello', false, false, false, false);  
      
    echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";  
    $callback = function($msg) {  
      echo " [x] Received ", $msg->body, "\n";  
    };  
      
    //在接收消息的时候调用$callback函数  
    $channel->basic_consume('hello', '', false, true, false, false, $callback);  
      
    while(count($channel->callbacks)) {  
        $channel->wait();  
    }

当我使用网上这段代码消费队列时,怎么会php脚本一直卡住,不会停止退出呢

阅读 213
评论
    0 个回答
    撰写回答

    登录后参与交流、获取后续更新提醒

    相似问题
    推荐文章