婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 使用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消息隊列的方法示例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 东平县| 亚东县| 聂荣县| 哈尔滨市| 宁晋县| 蓬莱市| 邳州市| 门源| 托克逊县| 奉贤区| 延津县| 遵义市| 攀枝花市| 华蓥市| 屏南县| 固镇县| 和平区| 长寿区| 丰城市| 府谷县| 仪征市| 伊川县| 江北区| 彩票| 沁阳市| 宜昌市| 隆林| 峨边| 东莞市| 奉新县| 郎溪县| 龙南县| 宁蒗| 沂南县| 定兴县| 桃源县| 稷山县| 嘉祥县| 木兰县| 建始县| 塘沽区|