国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

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

2024-05-05 00:04:06
字體:
來源:轉載
供稿:網友

本文實例講述了使用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.rpmyum 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教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 抚州市| 房产| 奉化市| 海兴县| 盘锦市| 富川| 隆昌县| 巴林右旗| 彰武县| 清徐县| 金山区| 郓城县| 井冈山市| 垫江县| 景洪市| 沁水县| 安顺市| 青州市| 巨鹿县| 昌吉市| 莒南县| 通榆县| 谢通门县| 沂源县| 葵青区| 清水河县| 凉城县| 南昌县| 雷州市| 沐川县| 绥中县| 屏边| 双牌县| 沾化县| 化隆| 如皋市| 隆回县| 房山区| 新建县| 政和县| 全南县|