欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

RabbitMQ Tutorials输出helloword

程序员文章站 2022-04-05 21:02:10
...

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的详细内容,更多请关注其它相关文章!