RabbitMQ是一个开源的遵循AMQP协议实现的基于 Erlang
语言编写,所以在安装 RabbitMQ 之前,必须安装新版本的 Erlang/OTP
。 标准的Red Hat
,Fedora
,CentOS
提供的是的 Erlang
旧版本,不能用于运行最新的RabbitMQ版本。
支持的系统版本参考 官方文档。
我的服务器系统是CentOS 7.5 64位,Centos 停止维护有三个版本,即:CentOS 6(2020年11月30日停止更新)、CentOS7(2024年6月30日停止更新)、CentOS 8(2021年底停止更新),解决方案:
- 在2024年6月之前基于两款新操作系统(CentOS Stream、RHEL订阅版),ubuntu、openEuler、Alibaba Cloud Linux 2(开源系统)进行系统适配开发、测试。
RabbitMQ 和 Erlang/OTP 兼容性:
RabbitMQ版本 | 最低要求的 Erlang/OTP | 支持的最大 Erlang/OTP | 说明 |
---|---|---|---|
3.12.0 | 25.0 | 26.0 | 此版本系列与Erlang 26兼容。 Erlang中对OpenSSL 3.0的支持被认为已经足够成熟,可以用于生产。 |
3.11.0 ~ 3.11.18 | 25.0 | 25.3.x | Erlang26引入了许多与网络和TLS相关的突破性变化。RabbitMQ与Erlang 26的兼容性将另行公布。 从Erlang25.1开始,Erlang中对OpenSSL 3.0的支持被认为已经足够成熟,可以用于生产。 25.0.2之前的Erlang 25受到CVE-2022-37026的影响,这是一种严重程度严重的CVE(CVSS 3.x基本分数:9.8) |
3.10.19 ~ 3.10.24 | 24.3.4.8 | 25.3.x | 24.3是Erlang 24中唯一维护(更新)的系列。 从Erlang25.1开始,Erlang中的OpenSSL 3.0支持被认为已经足够成熟,可以考虑用于生产。 25.0.2之前的Erlang 25和24.3.4.2之前的24受到CVE-2022-37026的影响,这是一种具有严重性的CVE(CVSS 3.x基本分数:9.8) |
3.10.14 ~ 3.10.18 | 24.3 | 25.2 | 24.3是Erlang 24中唯一维护(更新)的系列。 从Erlang25.1开始,Erlang中的OpenSSL 3.0支持被认为已经足够成熟,可以考虑用于生产。 25.0.2之前的Erlang 25和24.3.4.2之前的24受到CVE-2022-37026的影响,这是一种具有严重性的CVE(CVSS 3.x基本分数:9.8) |
3.10.8 ~ 3.10.13 | 24.2 | 25.2 | 从Erlang25.1开始,Erlang中的OpenSSL 3.0支持被认为已经足够成熟,可以考虑用于生产。 25.0.2之前的Erlang 25和24.3.4.2之前的24受到CVE-2022-37026的影响,这是一种具有严重性的CVE(CVSS 3.x基本分数:9.8) |
3.10.5 ~ 3.10.7 | 23.2 | 25.2 | 25.0.2之前的Erlang 25和24.3.4.2之前的24受到CVE-2022-37026的影响,这是一种具有严重性的CVE(CVSS 3.x基本分数:9.8) Erlang 23支持已于2022年7月31日停止。 |
3.10.0 ~ 3.10.4 | 23.2 | 24.3 | Erlang 23支持已于2022年7月31日停止。 |
官网下载地址:Erlang、RabbitMQ。
除了官网,还可以使用 packagecloud 的下载地址。
由于我的服务器系统是CentOS 7.5 64位,所以必须选择支持CentOS 7的Erlang 和 RabbitMQ 版本,下载包的名字中的 el7,el8,el9分别代表CentOS7,CentOS8,CentOS9;我这里下载的是旧版本: erlang-23.3.4.11-1.el7.x86_64.rpm
和 rabbitmq-server-3.10.0-1.el7.noarch.rpm
。
rmp包可以直接下载,使用 SCP 上传上去,又或者直接使用 wget 下载。
[root@VM-0-12-centos ~]# wget --content-disposition "https://packagecloud.io/rabbitmq/erlang/packages/el/7/erlang-23.3.4.11-1.el7.x86_64.rpm/download.rpm?distro_version_id=140"
[root@VM-0-12-centos ~]# rpm -ivh erlang-23.3.4.11-1.el7.x86_64.rpm
warning: erlang-23.3.4.11-1.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 6026dfca: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:erlang-23.3.4.11-1.el7 ################################# [100%]
[root@VM-0-12-centos ~]#
[root@VM-0-12-centos ~]# erl -v # 安装成功
Erlang/OTP 23 [erts-11.2.2.10] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe]
Eshell V11.2.2.10 (abort with ^G)
1>
[root@VM-0-12-centos ~]#
[root@VM-0-12-centos ~]# wget --content-disposition "https://packagecloud.io/rabbitmq/rabbitmq-server/packages/el/7/rabbitmq-server-3.10.0-1.el7.noarch.rpm/download.rpm?distro_version_id=140"
[root@VM-0-12-centos ~]# rpm -ivh rabbitmq-server-3.10.0-1.el7.noarch.rpm
warning: rabbitmq-server-3.10.0-1.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 6026dfca: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:rabbitmq-server-3.10.0-1.el7 ################################# [100%]
[root@VM-0-12-centos ~]#
[root@VM-0-12-centos ~]#
[root@VM-0-12-centos ~]# systemctl start rabbitmq-server # 启动rabbitmq
[root@VM-0-12-centos ~]# systemctl status rabbitmq-server # 查看rabbitmq状态
● rabbitmq-server.service - RabbitMQ broker
Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2023-06-12 17:26:18 CST; 8min ago
Main PID: 14354 (beam.smp)
CGroup: /system.slice/rabbitmq-server.service
├─14354 /usr/lib64/erlang/erts-11.2.2.10/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -sbwt none -sb...
├─14369 erl_child_setup 32768
├─14394 /usr/lib64/erlang/erts-11.2.2.10/bin/epmd -daemon
├─14414 inet_gethost 4
└─14415 inet_gethost 4
Jun 12 17:26:17 VM-0-12-centos rabbitmq-server[14354]: Doc guides: https://rabbitmq.com/documentation.html
Jun 12 17:26:17 VM-0-12-centos rabbitmq-server[14354]: Support: https://rabbitmq.com/contact.html
Jun 12 17:26:17 VM-0-12-centos rabbitmq-server[14354]: Tutorials: https://rabbitmq.com/getstarted.html
Jun 12 17:26:17 VM-0-12-centos rabbitmq-server[14354]: Monitoring: https://rabbitmq.com/monitoring.html
Jun 12 17:26:17 VM-0-12-centos rabbitmq-server[14354]: Logs: /var/log/rabbitmq/[email protected]
Jun 12 17:26:17 VM-0-12-centos rabbitmq-server[14354]: /var/log/rabbitmq/rabbit@VM-0-12-centos_upgrade.log
Jun 12 17:26:17 VM-0-12-centos rabbitmq-server[14354]: <stdout>
Jun 12 17:26:17 VM-0-12-centos rabbitmq-server[14354]: Config file(s): (none)
Jun 12 17:26:18 VM-0-12-centos systemd[1]: Started RabbitMQ broker.
Jun 12 17:26:18 VM-0-12-centos rabbitmq-server[14354]: Starting broker... completed with 3 plugins.
[root@VM-0-12-centos ~]#
参考其他博客时,都说需要安装 socat 依赖,但是我这里直接安装成功,如果有报错的的话就安装一下:
yum install -y socat
安装管理工具RabbitMQ-Plugins:
rabbitmq-plugins enable rabbitmq_management
接下来可直接查看下面的 【添加用户账号及权限并登陆】。
packagecloud也是提供了快速安装方式的RabbitMQ,安装的时候我发现脚本它会自动选择最packagecloud中适合当前系统的最高版本。
erlang
:curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
packagecloud脚本
准备安装 rabbitmq server
:curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
erlang
:yum -y install erlang
rabbitmq server
:yum -y install rabbitmq-server
systemctl start rabbitmq-server
systemctl status rabbitmq-server
rabbitmq-plugins enable rabbitmq_management
使用 15672端口
打开管理网页:添加 RabbitMQ 用户,并设置权限:
rabbitmqctl add_user [username] [password] # 添加用户账号
rabbitmqctl set_user_tags [username] administrator # 给用户添加权限
[root@VM-0-12-centos ~]# rabbitmqctl add_user rabbitmq rabbitmq
Adding user "rabbitmq" ...
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
[root@VM-0-12-centos ~]# rabbitmqctl set_user_tags rabbitmq administrator
Setting tags for user "rabbitmq" to [administrator] ...
[root@VM-0-12-centos ~]#
RabbitMQ常用命令:
查看RabbitMQ状态:
rabbitmqctl status
启动RabbitMQ服务:
systemctl start rabbitmq-server
停止RabbitMQ服务:
systemctl stop rabbitmq-server
重启RabbitMQ服务:
systemctl restart rabbitmq-server
查看RabbitMQ用户列表:
rabbitmqctl list_users
删除RabbitMQ用户:
rabbitmqctl delete_user [username]
修改RabbitMQ用户密码:
rabbitmqctl [oldpassword] [username] [newpassword]
如果需要熟悉不同安装方式,或者版本不兼容的话需要卸载:
# 卸载前先停掉rabbitmq服务
service rabbitmq-server stop
# 查看rabbitmq安装的相关列表
yum list | grep rabbitmq
# 卸载rabbitmq已安装的相关内容
yum -y remove rabbitmq-server.noarch
查看erlang安装的相关列表
yum list | grep erlang
卸载erlang已安装的相关内容
卸载erlang已安装的相关内容
yum -y remove erlang-*
yum remove erlang.x86_64
Windows 安装直接在官网中下载exe应用程序,这里我就直接下载了最新版本:otp_win64_26.0.1.exe
和 rabbitmq-server-3.12.0.exe
(参考上面RabbitMQ 和 Erlang/OTP 兼容性)。
下载erlang:
下载成功后直接双击otp_win64_26.0.1.exe
开始安装(一直next即可,我这里安装位置改到了D盘),安装成功后如下:
和erlang 一样,直接双击应用程序开始安装(一直next,只改了安装位置),安装成功后如下:
环境变量PATH追加 rabbitmq 的 sbin
路径:
安装管理工具RabbitMQ-Plugins:
访问http://localhost:15672/
,(默认账号:guest,密码:guest)就能进入RabbitMQ管理界面:
如果PHP环境下使用 RabbitMQ 的话,要先在本地安装 php-amqplib
扩展,这个对应的是 amqp
扩展,扩展下载地址。
Linux系统下 php 操作 rabbitmq
需要安装 amqp
扩展,但是安装 amqp
扩展前需要安装 rabbitmq-c
。
rabbitmq-c是一个用于C语言的,与AMQP server进行交互的client库,AMQP协议为版本0-9-1。rabbitmq-c与server进行交互前需要首先进行login操作,在操作后,可以根据AMQP协议规范,执行一系列操作。
我个人理解就是 php 底层是 C 语言, 而rabbitmq 是基于 erlang 语言,所以abbitmq-c扩展就是用于php与erlang的交互。
rabbitmq-c 扩展下载地址。
cd /usr/local
git clone https://github.com/alanxz/rabbitmq-c.git
cd /usr/local/rabbitmq-c
mkdir build && cd build \
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rabbitmq-c ..
cmake --build . --target install
cd /usr/local/rabbitmq-c/lib64
cp /usr/local/rabbitmq-c/lib64/librabbitmq.so /usr/lib
cp /usr/local/rabbitmq-c/lib64/librabbitmq.so.4 /usr/lib
echo "include /usr/local/lib" >> /etc/ld.so.conf
ldconfig
如果openssl版本过低,下载不了,就直接浏览器下载,SCP上传一下
[root@VM-0-12-centos local]# wget -c https://github.com/alanxz/rabbitmq-c/archive/refs/tags/v0.13.0.tar.gz
[root@VM-0-12-centos local]# tar zxf v0.13.0.tar.gz
[root@VM-0-12-centos local]# cd /usr/local/rabbitmq-c-0.13.0/
[root@VM-0-12-centos rabbitmq-c-0.13.0]# mkdir build && cd build
[root@VM-0-12-centos build]# ls
CMakeCache.txt CMakeFiles
[root@VM-0-12-centos build]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rabbitmq-c ..
...
[root@VM-0-12-centos build]# cmake --build . --target install
...
[root@VM-0-12-centos build]# cd /usr/local/rabbitmq-c/lib64/
[root@VM-0-12-centos lib64]# cp /usr/local/rabbitmq-c/lib64/librabbitmq.so /usr/lib
[root@VM-0-12-centos lib64]# cp /usr/local/rabbitmq-c/lib64/librabbitmq.so.4 /usr/lib
[root@VM-0-12-centos lib64]# echo "include /usr/local/lib" >> /etc/ld.so.conf
[root@VM-0-12-centos lib64]# ldconfig
[root@VM-0-12-centos lib64]#
[root@VM-0-12-centos build]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rabbitmq-c ..
CMake Error at CMakeLists.txt:4 (cmake_minimum_required):
CMake 3.12...3.18 or higher is required. You are running version 2.8.12.2
-- Configuring incomplete, errors occurred!
[root@VM-0-12-centos build]# cmake --version
cmake version 2.8.12.2
解决方法:
cmake-3.12.4.tar.gz
:[root@VM-0-12-centos ~]# wget https://cmake.org/files/v3.12/cmake-3.12.4.tar.gz
[root@VM-0-12-centos ~]# tar zxf cmake-3.12.4.tar.gz
[root@VM-0-12-centos ~]# cd cmake-3.12.4/
[root@VM-0-12-centos cmake-3.12.4]# ./bootstrap
...
[root@VM-0-12-centos cmake-3.12.4]# make && make install
...
[root@VM-0-12-centos cmake-3.12.4]# cmake --version
cmake version 3.12.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@VM-0-12-centos cmake-3.12.4]#
解决办法:
[root@VM-0-12-centos local]# wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
[root@VM-0-12-centos local]# tar -zxf openssl-1.1.1g.tar.gz
[root@VM-0-12-centos local]# cd openssl-1.1.1g
[root@VM-0-12-centos openssl-1.1.1g]# ./config --prefix=/usr/local/openssl shared zlib
...
[root@VM-0-12-centos openssl-1.1.1g]# make depend
[root@VM-0-12-centos openssl-1.1.1g]# make && make install
...
[root@VM-0-12-centos openssl-1.1.1g]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
[root@VM-0-12-centos openssl-1.1.1g]# ln -s /usr/local/openssl/include/openssl /usr/include/openssl
[root@VM-0-12-centos openssl-1.1.1g]# echo "/usr/local/ssl/lib" >> /etc/ld.so.conf # 更新动态链接库数据
[root@VM-0-12-centos openssl-1.1.1g]# ldconfig -v # 重新加载动态链接库
[root@VM-0-12-centos openssl-1.1.1g]# ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib
[root@VM-0-12-centos openssl-1.1.1g]# ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib
[root@VM-0-12-centos openssl-1.1.1g]# openssl version
OpenSSL 1.1.1g 21 Apr 2020
[root@VM-0-12-centos lib]#
[root@VM-0-12-centos ~]# wget http://pecl.php.net/get/amqp-1.11.0.tgz
[root@VM-0-12-centos ~]# tar -zxf amqp-1.11.0.tgz
[root@VM-0-12-centos ~]# cd amqp-1.11.0/
[root@VM-0-12-centos amqp-1.11.0]# ls
amqp_basic_properties.c amqp_envelope.c amqp_type.h
amqp_basic_properties.h amqp_envelope.h benchmark.php
amqp.c amqp_exchange.c config.m4
amqp_channel.c amqp_exchange.h config.w32
amqp_channel.h amqp_methods_handling.c CREDITS
amqp_connection.c amqp_methods_handling.h LICENSE
amqp_connection.h amqp_queue.c php5_support.h
amqp_connection_resource.c amqp_queue.h php7_support.h
amqp_connection_resource.h amqp_timestamp.c php_amqp.h
amqp_decimal.c amqp_timestamp.h stubs
amqp_decimal.h amqp_type.c tests
[root@VM-0-12-centos amqp-1.11.0]#
解压后,使用phpize安装扩展,下面的路径换成自己的:
[root@VM-0-12-centos amqp-1.11.0]# find / -name phpize
/usr/local/php/bin/phpize
/usr/bin/phpize
[root@VM-0-12-centos amqp-1.11.0]# /usr/local/php/bin/phpize
[root@VM-0-12-centos amqp-1.11.0]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c
...
[root@VM-0-12-centos amqp-1.11.0]# make && make install
...
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/
[root@VM-0-12-centos amqp-1.11.0]#
修改配置文件php.ini,追加以下内容:
extension = amqp.so
重启php-fpm,查看是否安装成功:
[root@VM-0-12-centos sockets]# php -m
[PHP Modules]
amqp
bcmath
Core
ctype
...
Windows 系统下 sockets
扩展是默认关闭的,但是Linux下 sockets
扩展是开启的,查看是否启用:
[root@VM-0-12-centos sockets]# php -m
[PHP Modules]
amqp
bcmath
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
gettext
hash
iconv
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib
[Zend Modules]
[root@VM-0-12-centos sockets]#
root@VM-0-12-centos ~]# cd /home/wwwroot/laravel/
[root@VM-0-12-centos laravel]# composer require vladimir-yuldashev/laravel-queue-rabbitmq
Cannot use vladimir-yuldashev/laravel-queue-rabbitmq's latest version v13.3.0 as it requires php ^8.0 which is not satisfied by your platform.
./composer.json has been updated
Running composer update vladimir-yuldashev/laravel-queue-rabbitmq
Loading composer repositories with package information
Updating dependencies
Lock file operations: 5 installs, 0 updates, 0 removals
- Locking paragonie/constant_time_encoding (v2.6.3)
- Locking paragonie/random_compat (v9.99.100)
- Locking php-amqplib/php-amqplib (v3.5.2)
- Locking phpseclib/phpseclib (3.0.19)
- Locking vladimir-yuldashev/laravel-queue-rabbitmq (v11.3.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 5 installs, 0 updates, 0 removals
- Installing paragonie/random_compat (v9.99.100): Extracting archive
- Installing paragonie/constant_time_encoding (v2.6.3): Extracting archive
- Installing phpseclib/phpseclib (3.0.19): Extracting archive
- Installing php-amqplib/php-amqplib (v3.5.2): Extracting archive
- Installing vladimir-yuldashev/laravel-queue-rabbitmq (v11.3.0): Extracting archive
4 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package fruitcake/laravel-cors is abandoned, you should avoid using it. No replacement was suggested.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: vladimir-yuldashev/laravel-queue-rabbitmq
Package manifest generated successfully.
78 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
No publishable resources for tag [laravel-assets].
Publishing complete.
No security vulnerability advisories found
Using version ^11.3 for vladimir-yuldashev/laravel-queue-rabbitmq
[root@VM-0-12-centos laravel]#
根据我的环境是 php7.3,选择的是64位NON Thread Safe(TS),不知道选择TS 还是 NTS的下面。
从2000年10月20日发布的第一个Windows版的PHP3.0.17开始的都是线程安全的版本,这是由于与Linux/Unix系统是采用多进程的工作方式不同的是Windows系统是采用多线程的工作方式。如果在IIS下以CGI方式运行PHP会非常慢,这是由于CGI模式是建立在多进程的基础之上的,而非多线程。一般我们会把PHP配置成以ISAPI的方式来运行,ISAPI是多线程的方式,这样就快多了。但存在一个问题,很多常用的PHP扩展是以Linux/Unix的多进程思想来开发的,这些扩展在ISAPI的方式运行时就会出错搞垮IIS。因此在IIS下CGI模式才是 PHP运行的最安全方式,但CGI模式对于每个HTTP请求都需要重新加载和卸载整个PHP环境,其消耗是巨大的。
为了兼顾IIS下PHP的效率和安全,微软给出了FastCGI的解决方案。FastCGI可以让PHP的进程重复利用而不是每一个新的请求就重开一个进程。同时FastCGI也可以允许几个进程同时执行。这样既解决了CGI进程模式消耗太大的问题,又利用上了CGI进程模式不存在线程安全问题的优势。
因此,如果是使用ISAPI的方式来运行PHP就必须用Thread Safe(线程安全)的版本;而用FastCGI模式运行PHP的话就没有必要用线程安全检查了,用None Thread Safe(NTS,非线程安全)的版本能够更好的提高效率。
下载解压后如下:
打开自己的php安装目录,因为我用的是phpstudy,安装了多个PHP环境,这里我以php7.3.4为例:
Admin@DESKTOP-CSH3FGN MINGW64 ~/Desktop
$ php -v
PHP 7.3.4 (cli) (built: Apr 2 2019 21:57:22) ( NTS MSVC15 (Visual C++ 2017) x64
)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans
Admin@DESKTOP-CSH3FGN MINGW64 ~/Desktop
$
接下来需要把解压后的 php_amqp.dll
和 rabbitmq.4.dll
,放到对应的目录:
php_amqp.dll
放到 E:\phpstudy_pro\Extensions\php\php7.3.4nts\ext
目录下;
rabbitmq.4.dll
放到 php.exe
同级目录,即 E:\phpstudy_pro\Extensions\php\php7.3.4nts
;
php.ini 配置文件中添加扩展 extension=php_amqp.dll
,并重启php:
phpinfo查看是否安装成功:
除了amqp
扩展,还需要启用 sockets
扩展,这个php自带的但是没有启用,删除配置文件的注释重启php就好;
重启PHP。
方式一:
composer require vladimir-yuldashev/laravel-queue-rabbitmq
方式二:
"require": {
"vladimir-yuldashev/laravel-queue-rabbitmq": "^11.3"
},
composer install
E:\work\laravel>composer require vladimir-yuldashev/laravel-queue-rabbitmq
Using version ^11.3 for vladimir-yuldashev/laravel-queue-rabbitmq
./composer.json has been updated
Running composer update vladimir-yuldashev/laravel-queue-rabbitmq
Loading composer repositories with package information
Updating dependencies
Lock file operations: 5 installs, 0 updates, 0 removals
- Locking paragonie/constant_time_encoding (v2.6.3)
- Locking paragonie/random_compat (v9.99.100)
- Locking php-amqplib/php-amqplib (v3.5.2)
- Locking phpseclib/phpseclib (3.0.19)
- Locking vladimir-yuldashev/laravel-queue-rabbitmq (v11.3.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 5 installs, 0 updates, 0 removals
- Downloading paragonie/random_compat (v9.99.100)
- Downloading paragonie/constant_time_encoding (v2.6.3)
- Downloading phpseclib/phpseclib (3.0.19)
- Downloading php-amqplib/php-amqplib (v3.5.2)
- Downloading vladimir-yuldashev/laravel-queue-rabbitmq (v11.3.0)
- Installing paragonie/random_compat (v9.99.100): Extracting archive
- Installing paragonie/constant_time_encoding (v2.6.3): Extracting archive
- Installing phpseclib/phpseclib (3.0.19): Extracting archive
- Installing php-amqplib/php-amqplib (v3.5.2): Extracting archive
- Installing vladimir-yuldashev/laravel-queue-rabbitmq (v11.3.0): Extracting archive
5 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package fruitcake/laravel-cors is abandoned, you should avoid using it. No replacement was suggested.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: vladimir-yuldashev/laravel-queue-rabbitmq
Package manifest generated successfully.
77 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
No publishable resources for tag [laravel-assets].
Publishing complete.
E:\work\laravel>
参考:Hello World。
composer.json
内容:
{
"require": {
"php-amqplib/php-amqplib": "2.6.1"
}
}
加载依赖:
composer install
send.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('Hello World!');
$channel->basic_publish($msg, '', 'hello');
echo " [x] Sent 'Hello World!'\n";
$channel->close();
$connection->close();
?>
receive.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 ($channel->is_open()) {
$channel->wait();
}
$channel->close();
$connection->close();
?>