首页  >  文章  >  后端开发  >  RabbitMQ Tutorials输出helloword

RabbitMQ Tutorials输出helloword

一个新手
一个新手原创
2017-10-12 09:16:562066浏览

Sending 发送方

$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
// 指定虚拟机
// $connection = new AMQPStreamConnection('localhost', 5672, 'test1', '123456', $vhost);
$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();

Receiving 收接方

$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
// 指定虚拟机
// $connection = new AMQPStreamConnection('localhost', 5672, 'test1', '123456', $vhost);
$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();
}

以上是RabbitMQ Tutorials输出helloword的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn