0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7+RabbitMQインストール手順

Last updated at Posted at 2019-05-30
yum install epel-release -y
yum update -y
yum install erlang -y
yum info erlang
rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
yum install wget -y
wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.6.14/rabbitmq-server-3.6.14-1.el7.noarch.rpm
yum install rabbitmq-server-3.6.14-1.el7.noarch.rpm -y
systemctl enable rabbitmq-server.service
systemctl start rabbitmq-server
systemctl status rabbitmq-server
rabbitmq-plugins enable rabbitmq_management
firewall-cmd  --permanent --add-port=15672/tcp
firewall-cmd  --permanent --add-port=80/tcp
firewall-cmd  --permanent --add-port=443/tcp
firewall-cmd --reload
rabbitmqctl add_user admin 任意のパスワード
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
http://xxx.xxx.xxx.xxx:15672/  adminでログインできればOK。

引き続き、PHPからキューを使えるようにする。

PHPが入っていなければ下記で入れる。

yum -y install vim-enhanced
yum update -y
yum install epel-release.noarch -y
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum install httpd -y
systemctl start httpd.service
systemctl enable httpd.service
yum --enablerepo=epel install libmcrypt -y
yum --enablerepo=remi-php71 install -y php php-cli php-devel php-common php-mbstring php-mysql php-fpm php-gd php-mcrypt php-opcache php-pdo php-xml php-intl php-zip php-pear php-bcmath

php-amqplib

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
yum install ansible -y
ansible --version
yum install git -y
composer require php-amqplib/php-amqplib 

送信処理 sender.php

<?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();

受信処理 receiver.php

<?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();
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?