rabbitMQ Mac下安装运行配置
rabbitMQ Mac下安装运行配置
AlexrabbitMQ mac下安装运行配置
- 安装
1
2wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.5.3/rabbitmq-server-mac-standalone-3.5.3.tar.gz
tar -zxvf rabbitmq-server-mac-standalone-3.5.3.tar.gz - 运行
1
./sbin/rabbitmq-server
- 使用rabbitMQ管理页面,Ctrl+C退出刚刚启动进程
1
2/rabbitmq-plugins enable rabbitmq_management //允许后台管理
./sbin/rabbitmq-server //再次启动服务 - 后台测试 地址
http://localhost:15672/
用户名和密码 是guest
/guest
php测试发送接收
- 创建一个目录
php
进入composer init
初始化composer composer.json
引入扩展1
2
3"require": {
"php-amqplib/php-amqplib": ">=2.6.1"
}- 执行安装
composer install
- vi send.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->queue_declare('hello', false, false, false, false);
$msg = new AMQPMessage('This is a message for key hello asdfasdfasd !');
$channel->basic_publish($msg, '', 'hello');
echo " [x] Sent 'Hello World!'\n";
$channel->close();
$connection->close(); - vi receive.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->queue_declare('hello', false, false, false, false);
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
$callback = function($msg) {
echo " [x] Received ", $msg->body, "\n";
};
$channel->basic_consume('hello', '', false, true, false, false, $callback);
while(count($channel->callbacks)) {
$channel->wait();
} - 命令行执行
php recevie.php
启动接收消息 - 新开一个窗口,命令行执行
php send.php
发送消息,这是receive这边将接收到send的消息。