<?php
use Bunny\Channel;
use Bunny\Message;
use Workerman\Worker;
use Workerman\RabbitMQ\Client;
require_once __DIR__ . '/../../vendor/autoload.php';
$worker = new Worker();
$worker->onWorkerStart = function() {
$options = array(
'host' => '120.0.0.1',
'port' => '5672',
'user' => 'admin',
'password' => 'admin',
'debug'=>true,
);
(new Client($options))->connect()->then(function (Client $client) {
return $client->channel();
})->then(function (Channel $channel) {
return $channel->queueDeclare('test', false, false, false, false)->then(function () use ($channel) {
return $channel;
});
})->then(function (Channel $channel) {
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
$channel->consume(
function (Message $message, Channel $channel, Client $client) {
echo " [x] Received ", $message->content, "\n";
print_R($message->content);
},
'test',
'',
false,
true
);
});
};
Worker::runAll();
服务器上有上报数据
看到你代码里连的是 120.0.0.1,是不是错了,应该连127.0.0.1 吧