注意事项:
1、accept.php消费者代码需要在命令行执行
2、'username'=>'asdf','password'=>'123456' 改成自己的帐号和密码
RabbitMQCommand.php操作类代码
<?php
/*
* amqp协议操作类,可以访问rabbitMQ
* 需先安装php_amqp扩展
*/
class RabbitMQCommand{
public $configs = array();
//交换机名称
public $exchange_name = '';
//队列名称
public $queue_name = '';
//路由名称
public $route_key = '';
/*
* 持久化,默认True
*/
public $durable = True;
/*
* 自动删除
* exchange is deleted when all queues have finished using it
* queue is deleted when last consumer unsubscribes
*
*/
public $autodelete = False;
/*
* 镜像
* 镜像队列,打开后消息会在节点之间复制,有master和slave的概念
*/
public $mirror = False;
private $_conn = Null;
private $_exchange = Null;
private $_channel = Null;
private $_queue = Null;
/*
* @configs array('host'=>$host,'port'=>5672,'username'=>$username,'password'=>$password,'vhost'=>'/')
*/
public function __construct($configs = array(), $exchange_name = '', $queue_name = '', $route_key = '') {
$this->setConfigs($configs);
$this->exchange_name = $exchange_name;
$this->queue_name = $queue_name;
$this->