php发golang接,php 发送消息,golang接收消息

use PhpAmqpLib\Connection\AMQPStreamConnection;

use PhpAmqpLib\Message\AMQPMessage;

class RabbitMQ_InventoryBatch

{

protected $_conn;

public function __construct()

{

$mq_config = new Zend_Config_Ini(APPLICATION_PATH . '/../application/configs/mq.ini', 'production',true);

$this->host = $mq_config->mq->host;

$this->port = $mq_config->mq->port;

$this->user = $mq_config->mq->user;

$this->pass = $mq_config->mq->pass;

//获得连接

$this->_conn = new AMQPStreamConnection($this->host, $this->port, $this->user, $this->pass);

}

public function pusher($msg_body){

$exchange = 'exchange1';

$queue = 'Inventory';

//建立mq通道

$channel = $this->_conn->channel();

/*

*

声明通道

name: $queue

passive: false

durable: true // the queue will survive server restarts

exclusive: false // the queue can be accessed in other channels

auto_delete: false //the queue won't be deleted once the channel is closed.

*/

$channel->queue_declare($queue, false, false, false, false);

/*

*

name: $exchange

type: direct

passive: false

durable: true // the exchange will survive server restarts

auto_delete: false //the exchange won't be deleted once the channel is closed.

*/

//fanout

$channel->exchange_declare($exchange, 'direct', false, true, false);

//绑定exchange

$channel->queue_bind($queue, $exchange);

if(empty($msg_body)) $msg_body = "Hello World!";

if(is_array($msg_body)){

$msg_body=serialize($msg_body);

}

$msg = new AMQPMessage($msg_body, array('content_type' => 'text/plain', 'delivery-mode' => 2));

$channel->basic_publish($msg, $exchange);

$channel->close();

$this->_conn->close();

}

}

![微信图片_20190731145511.png](https://static.studygolang.com/190731/07049a110466558d3655e2d616c45c45.png)

有疑问加站长微信联系(非本文作者))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值