使用PHP访问RabbitMQ消息队列
来源:互联网 发布:马鞍山网络大学招聘 编辑:程序博客网 时间:2024/05/24 02:38
扩展安装
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访问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);
}
http://www.wuweixin.com/2013/06/04/php-rabbitmq-amqp-extension/
0 0
- 使用PHP访问RabbitMQ消息队列
- 使用PHP访问RabbitMQ消息队列
- 基于PHP使用rabbitmq实现消息队列
- php RabbitMQ消息队列
- 使用rabbitmq消息队列
- 消息队列-RabbitMq(PHP)
- 消息队列-RabbitMq(PHP)
- RabbitMQ+PHP消息队列系统
- php amqp 消息队列 RabbitMQ 基本概念(二)
- php amqp 消息队列 RabbitMQ 安装(一)
- rabbitmq消息队列php实际应用
- RabbitMQ+PHP 消息队列环境配置
- RabbitMQ+PHP 消息队列环境配置
- RabbitMq 消息队列的安装、使用 、原理
- 在C#中使用消息队列RabbitMQ
- .Net下RabbitMQ消息队列的使用
- C#.NET使用消息队列RabbitMQ
- 消息队列 RabbitMQ 与 Spring 整合使用
- Struts2的工作流程
- 统计学习方法(3)——KNN,KD树及其Python实现
- oracle视图、列转行、前几个月、相差秒数、自增主键
- 【JavaScript】3.语法
- uboot的几种启动方式的配置方法。
- 使用PHP访问RabbitMQ消息队列
- 深入分析Java ClassLoader原理
- Python设计模式(四) -- 模板方法模式
- 递归,递推,迭代区别:
- Friends
- HTTP/1.1 协议Expect: 100-continue
- Python并发编程eventlet
- "Accordian" Patience UVA
- IntelliJ IDEA乱码调整