Rabbitmq的php实现消息发送和接收

send.php

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

receive.php

channel();

$channel->queue_declare('hello', false, false, false, false);

$callback = function ($msg) {
    echo '[*] Received ' . $msg->body .  '\n';
};

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

echo " [*] Waiting for messages. To exit press CTRL+C\n";

你可能感兴趣的:(Rabbitmq的php实现消息发送和接收)