校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > 使用PHP訪問RabbitMQ消息隊列的方法示例

使用PHP訪問RabbitMQ消息隊列的方法示例

熱門標簽:智能外呼電銷系統 合肥外呼系統app 沈陽人工智能電銷機器人公司 拉薩打電話機器人 h5 地圖標注 高識別電銷機器人 哈爾濱400電話辦理到易號網 電銷機器人-快迭智能 寶安400電話辦理

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

擴展安裝

PHP訪問RabbitMQ實際使用的是AMQP協議,所以我們只要安裝epel庫中的php-pecl-amqp這個包即可

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();

隊列建立

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

隊列綁定

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

消息發送

?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);
}

更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP數據結構與算法教程》、《php程序設計算法總結》、《php字符串(string)用法總結》、《PHP數組(Array)操作技巧大全》、《PHP常用遍歷算法與技巧總結》及《PHP數學運算技巧總結》

希望本文所述對大家PHP程序設計有所幫助。

您可能感興趣的文章:
  • php實現通過stomp協議連接ActiveMQ操作示例
  • php ActiveMQ的安裝與使用方法圖文教程
  • PHP使用ActiveMQ實現消息隊列的方法詳解
  • PHP使用ActiveMQ實例
  • PHP Beanstalkd消息隊列的安裝與使用方法實例詳解
  • PHP高級編程之消息隊列原理與實現方法詳解
  • php+redis實現消息隊列功能示例
  • PHP+RabbitMQ實現消息隊列的完整代碼
  • php實現websocket實時消息推送
  • php 使用ActiveMQ發送消息,與處理消息操作示例

標簽:巴中 山東 成都 威海 林芝 泰州 張家口 梅州

巨人網絡通訊聲明:本文標題《使用PHP訪問RabbitMQ消息隊列的方法示例》,本文關鍵詞  使用,PHP,訪問,RabbitMQ,消息,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《使用PHP訪問RabbitMQ消息隊列的方法示例》相關的同類信息!
  • 本頁收集關于使用PHP訪問RabbitMQ消息隊列的方法示例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 噶尔县| 项城市| 峨山| 阳泉市| 崇信县| 乌拉特中旗| 和政县| 天峨县| 福清市| 游戏| 察雅县| 中山市| 宁夏| 尉犁县| 元氏县| 大城县| 凉城县| 凭祥市| 肥东县| 襄樊市| 广平县| 根河市| 虎林市| 大渡口区| 泰州市| 山东省| 绥棱县| 田东县| 胶州市| 多伦县| 罗定市| 平塘县| 南涧| 长垣县| 宣恩县| 延寿县| 柳林县| 中牟县| 寻甸| 色达县| 玉门市|