最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用PHP訪問RabbitMQ消息隊(duì)列的方法示例

 更新時(shí)間:2018年06月06日 14:30:07   作者:Zach-vip  
這篇文章主要介紹了使用PHP訪問RabbitMQ消息隊(duì)列的方法,結(jié)合實(shí)例形式分析了RabbitMQ消息隊(duì)列的相關(guān)擴(kuò)展安裝、隊(duì)列建立、隊(duì)列綁定、消息發(fā)送、消息接收等相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了使用PHP訪問RabbitMQ消息隊(duì)列的方法。分享給大家供大家參考,具體如下:

擴(kuò)展安裝

PHP訪問RabbitMQ實(shí)際使用的是AMQP協(xié)議,所以我們只要安裝epel庫(kù)中的php-pecl-amqp這個(gè)包即可

rpm -ivh http://mirror.neu.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install php-pecl-amqp

交換建立

<?php
$connection = new AMQPConnection();
$connection->connect();
$channel = new AMQPChannel($connection);
$exchange = new AMQPExchange($channel);
$exchange->setName('exchange1');
$exchange->setType('fanout');
$exchange->declare();

隊(duì)列建立

<?php
$connection = new AMQPConnection();
$connection->connect();
$channel = new AMQPChannel($connection);
$queue = new AMQPQueue($channel);
$queue->setName('queue1');
$queue->declare();

隊(duì)列綁定

<?php
$connection = new AMQPConnection();
$connection->connect();
$channel = new AMQPChannel($connection);
$queue = new AMQPQueue($channel);
$queue->setName('queue1');
$queue->declare();
$queue->bind('exchange1', 'routekey');

消息發(fā)送

<?php
$connection = new AMQPConnection();
$connection->connect();
$channel = new AMQPChannel($connection);
$exchange = new AMQPExchange($channel);
$exchange->setName('exchange5');
$exchange->setType('fanout');
$exchange->declare();
for($i = 0; $i < 2000000; $i++) {
 $exchange->publish("message $i", "routekey");
}

消息接收

<?php
$connection = new AMQPConnection();
$connection->connect();
$channel = new AMQPChannel($connection);
$queue = new AMQPQueue($channel);
$queue->setName('queue1');
$queue->declare();
$queue->bind('exchange1', 'routekey');
while (true) {
  $queue->consume(function($envelope, $queue){
   echo $envelope->getBody(), PHP_EOL;
  }, AMQP_AUTOACK);
}

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP常用遍歷算法與技巧總結(jié)》及《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

黔西县| 民权县| 高清| 庄浪县| 从化市| 互助| 云梦县| 同德县| 平度市| 东乡| 射洪县| 伽师县| 崇明县| 杭州市| 巩义市| 平乐县| 江门市| 南陵县| 建始县| 石狮市| 尚志市| 漳州市| 高碑店市| 永州市| 青岛市| 桦甸市| 望江县| 蒙城县| 磐安县| 宜兰市| 贡山| 会同县| 乌海市| 荔波县| 武定县| 都昌县| 德兴市| 崇仁县| 中西区| 濉溪县| 武威市|