1,要使用rabbitMQ隊列需要引入文件
require_once __DIR__.'/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPReader;
2,若已創建隊列和交換機,不能加$ch->exchange_declare($exchange, $mqtype, false, true, false);聲明,加這行需要添加交換機和隊列的權限
3,大致代碼
$conn = new AMQPConnection($this->ServerAddress, $this->Port, $this->mquser, $this->mqpassw, $this->vhost);//建立連接
$ch = $conn->channel();
//$ch->exchange_declare($exchange, $mqtype, false, true, false);//聲明交換機
$msg = new AMQPMessage(json_encode($msg_body),array('content_type' => 'text/plain'));
$ch->basic_publish($msg, $exchange); //推送消息
$ch->close();
$conn->close(); //關閉連接