送信側
send.php
require_once __DIR__ . '/vendor/autoload.php'; use PhpAmqpLib\Connection\AMQPStreamConnection; use PhpAmqpLib\Message\AMQPMessage; // コネクションの確立 $connection = new AMQPStreamConnection('192.168.33.10', 5672, 'guest', 'guest'); $channel = $connection->channel(); $channel->queue_declare('hello', false, false, false, false); $msg = new AMQPMessage('Whats up'); $channel->basic_publish($msg, '', 'hello'); echo "[x] sent 'Hello World!'\n"; $channel->close();
受信側
require_once __DIR__ . '/vendor/autoload.php'; use PhpAmqpLib\Connection\AMQPStreamConnection; $connection = new AMQPStreamConnection('192.168.33.10', 5672, 'guest', 'guest'); $channel = $connection->channel(); $channel->queue_declare('hello', false, false, false, false); echo "[*] Waiting for messages. To exit press CTR+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 recieve.php
PHP Fatal error: Uncaught PhpAmqpLib\Exception\AMQPIOException: stream_socket_client(): unable to connect to tcp://192.168.33.10:5672 (Connection refused) in /home/vagrant/dev/mailer/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:111
サーバにRabbitMQをインストールしないとダメなのか。。