Try RabbitMQ + PHP on CentOS

A note when I tried RabbitMQ to introduce asynchronous processing in PHP.

MQ preparation

RabbitMQ installation

yum --enablerepo=epel -y install rabbitmq-server
systemctl start rabbitmq-server
systemctl enable rabbitmq-server

Add user

rabbitmqctl add_user mquser password
rabbitmqctl list_users

Add virtual host

rabbitmqctl add_vhost myhost
rabbitmqctl list_vhosts

Permission settings

rabbitmqctl set_permissions -p myhost mquser ".*" ".*" ".*"
rabbitmqctl list_permissions -p myhost

PHP program preparation (sender & receiver)

php library installation

yum -y install --enablerepo=epel,remi-php73 php php-bcmath composer

composer installation

mkdir mq
cd mq
composer require php-amqplib/php-amqplib
composer install


Send application creation

vi send_msg.php
require_once __DIR__ . '/vendor/autoload.php';

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

$connection = new AMQPStreamConnection('', 5672, 'mquser', 'password', 'myhost');

$channel = $connection->channel();
$channel->queue_declare('Hello_World', false, false, false, false);

$msg = new AMQPMessage('Hello RabbitMQ World!');
$channel->basic_publish($msg, '', 'Hello_World');
echo " [x] Sent 'Hello_World'\n";



php send_msg.php


Create receiving application

vi receive_msg.php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;

$connection = new AMQPStreamConnection('', 5672, 'mquser', 'password', 'myhost');
$channel = $connection->channel();

$channel->queue_declare('Hello_World', 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_World', '', false, true, false, false, $callback);

while(count($channel->callbacks)) {


php receive_msg.php
(CTRL+Stop at C)

Recommended Posts

Try RabbitMQ + PHP on CentOS
Try OpenLiteSpeed on CentOS8
Try DPDK20 SDK on CentOS7 â‘ Install
Try putting CentOS 8 on Raspberry Pi 3
Try DPDK20 SDK on CentOS7 (2) Control DPDK driver
How to install beta php8.0 on CentOS8
OpenVPN on CentOS 8
Command to install nginx / PHP7 / php-fpm on CentOS7
Try local file search using Fess on CentOS7
Try local file search using Fess on CentOS8
Maven on CentOS 7 tutorial
Try DisplayLink on Ubuntu 20.04
Docker installation on CentOS 6
Use perltidy on CentOS 8
Install Golang on CentOS 8
Install Neo4j 4.1.3 on centOS
Tomcat v8 on CentOS7
Install Vertica 10.0 on CentOS 6.10
Zabbix 5 installation on CentOS 8
Use mod_auth_cas on CentOS 8
Install PostgreSQL 12 on Centos8
Install nginx on centOS7
Install Python 3 on CentOS 7
Install kuromoji on CentOS7
Use bat on Centos.
Jetty v8 on CentOS7
OpenJDK installation on CentOS 7
Install Mattermost on CentOS 7
Install PostGIS 2.5.5 on CentOS7
Try actions on GitHub [actions]
Install jpndistrict on CentOS 7
Install Redmine 4.1.1 on CentOS 7
Smokeping Install on CentOS7
Install PostgreSQL 13 on CentOS 7.5
Make exFat available on CentOS 7
Try Docker on Windows 10 Home
Install OpenFOAM v2006 on CentOS
Set up Gitolite on CentOS 7
Install Jenkins on Docker's CentOS
Install Apache on CentOS on VirtualBox
Introducing Let's Encrypt on CentOS 7
Java version change on CentOS
Install Ruby 2.7 on CentOS 7 (SCL)
Perform log rotation on centos
Try Spring Boot on Mac
[Ruby on Rails] Read try (: [],: key)
How to deploy Laravel on CentOS 7
Enable Openjdk10 and maven on CentOS
Try using Redmine on Mac docker
Install Ruby 2.5 on CentOS 7 using SCL
Install Java Open JDK 8 on CentOS 7
Try Quarkus on IBM Cloud Shell
WordPress with Docker Compose on CentOS 8
Upgrade from MYSQL5.7 to 8.0 on CentOS 6.7
How to install MariaDB 10.4 on CentOS 8
Install apache 2.4.46 from source on CentOS7
Steps to install MySQL 8 on CentOS 8
Use the iostat command on CentOS 8
Try Docker on Windows Home (September 2020)
Try running Spring Boot on Kubernetes
I tried installing CentOS 8 on ESXi 6.7