php使用rabbitMQ遇到的坑


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(); //關閉連接


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM