$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();
$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中文網其他相關文章!