一起源码网

标题: RabbitMQ Tutorials输出helloword [打印本页]

作者: 云文章    时间: 2020-5-11 21:30
标题: RabbitMQ Tutorials输出helloword

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!'
";

$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', "
";
$callback = function($msg) {
  echo " [x] Received ", $msg->body, "
";
};

$channel->basic_consume('hello', '', false, true, false, false, $callback);

while(count($channel->callbacks)) {
    $channel->wait();
}


作者: yy890816    时间: 2022-10-6 18:12
怎么用源码做软件




欢迎光临 一起源码网 (https://www.171739.xyz/) Powered by Discuz! X3.3