Listing exchanges
$ sudo rabbitmqctl list_exchanges
Listing exchanges …
direct
amq.direct direct
amq.fanout fanout
amq.headers headers
amq.match headers
amq.rabbitmq.log topic
amq.rabbitmq.trace topic
amq.topic topic
…done.
emit_log.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('logs', 'fanout', false, false, false); $data = implode('', array_slice($argv, 1)); if(empty($data)){ $data = "info:Hello World!"; } $msg = new AMQPMessage($data); $channel->basic_publish($msg, 'logs'); echo '[x]Sent', $data, "\n"; $channel->close(); $connection->close();
receive_logs.php
require_once __DIR__ . '/vendor/autoload.php'; use PhpAmqpLib\Connection\AMQPStreamConnection; $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest'); $channel = $connection->channel(); $channel->queue_declare('logs', 'fanout', false, false, false); list($queue_name,,) = $channel->queue_declare("", false, false, true, false); $channel->queue_bind($queue_name, 'logs'); echo " [*] Waiting for messages. To exit press CTRL+C\n"; $callback = function ($msg) { echo ' [x]', $msg->body, "\n"; }; $channel->basic_consume($queue_name, '', false, true, false, false, $callback); while ($channel->is_consuming()) { $channel->wait(); } $channel->close();
$ php receive_logs.php
PHP Fatal error: Uncaught PhpAmqpLib\Exception\AMQPProtocolChannelException: NOT_FOUND – no queue ‘logs’ in vhost ‘/’ in /home/vagrant/dev/mailer/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php:216
なんやこれは。。。よーわからん。。