Laravel: 监听 AMQP 队列

Laravel: listening AMQP queue

如何在 laravel 中实现监听队列? 我正在使用 AMQP library

在 RabbitMQ 文档中,这看起来像这样:

$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();

$channel->queue_declare('hello', false, false, false, false);

$callback = function($msg) {
  echo " [x] Received ", $msg->body, "\n";
};

$channel->basic_consume('hello', '', false, true, false, false, $callback);

while(count($channel->callbacks)) {
    $channel->wait();
}

p.s。对不起我的英语:|

我建议安装 AMQP Laravel 驱动程序。有一些:

它会做所有事情。