TP使用RabbitMq队列
最近学习rabbitmq,看了很多文章,写的都太乱,转载了一个比较不错的
我是windows10所以需要先安装Erlang,然后再安装RabbitMq服务端,TP根目录使用composer安装扩展
composer require php-amqplib/php-amqplib
<?php
//接收端 需要守护进程运行
use PhpAmqpLib\Connection\AMQPStreamConnection;
class MessageConsume
{
protected $consumerTag = 'consumer';
protected $exchange = 'router';
protected $queue = 'msgs';
/*
*关闭
*/
function shutdown($channel, $connection)
{
$channel->close();
$connection->close();
}
/*
*回调处理信息
*/
function process_message($message)
{
if ($message->body !== 'quit') {
echo $message->body;
}
//手动应答
$message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag'])