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