文章目录
- 安装rabbitmq
- php脚本连接测试
- php 安装驱动
安装rabbitmq
php 安装
sudo yum -y install yum-utils
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --enable remi-php74
sudo yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis php-memcache php-memcached php-mongodb php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis快速安装docker run -d -p 15672:15672 -p 5672:5672 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=ehkafesfsefesfesfHfadfadfsdfaiA9eJfpp --name rabbitmq --hostname=rabbitmqhostone rabbitmq:managementphp 连接rabbitmq 的插件
yum install -y php-amqp php-pecl-amqp
php脚本连接测试
<?php
$conn = [// Rabbitmq 服务地址'host' => '127.0.0.1',// Rabbitmq 服务端口'port' => '5672',// Rabbitmq 帐号'login' => 'admin',// Rabbitmq 密码'password' => 'AdminkTJLdefesfeL0u','vhost'=>'/'
];//创建连接和channel
$conn = new AMQPConnection($conn);
if(!$conn->connect()) {die("Cannot connect to the broker!\n");
}
$channel = new AMQPChannel($conn);// 用来绑定交换机和队列
$routingKey = 'key_1';$ex = new AMQPExchange($channel);
// 交换机名称
$exchangeName = 'ex1';
$ex->setName($exchangeName);// 设置交换机类型
$ex->setType(AMQP_EX_TYPE_DIRECT);
// 设置交换机是否持久化消息
$ex->setFlags(AMQP_DURABLE);
$ex->declare();for($i=0; $i<5; ++$i){echo "Send Message:".$ex->publish(date('H:i:s')."用户".$i."注册" , $routingKey )."\n";
}
php 安装驱动
参考文档: http://www.woodlsy.com/article/index.html?id=14