49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
namespace app\process;
|
|
|
|
|
|
use Bunny\Channel;
|
|
use Bunny\Message;
|
|
use Workerman\Worker;
|
|
use Workerman\RabbitMQ\Client;
|
|
|
|
|
|
class RabbConsumApplySmsTemp
|
|
{
|
|
public function onWorkerStart()
|
|
{
|
|
$worker = new Worker();
|
|
$worker->eventLoop = \Workerman\Events\Fiber::class;
|
|
$worker->onWorkerStart = function () {
|
|
$host = config('cons.mq.host');
|
|
$port = config('cons.mq.port');
|
|
$user = config('cons.mq.user');
|
|
$password = config('cons.mq.password');
|
|
$queue = config('cons.mq.queue_t') . '-apply.sms.temp';
|
|
$client = Client::factory([
|
|
'host' => $host,
|
|
'port' => $port,
|
|
'user' => $user,
|
|
'password' => $password,
|
|
'vhost' => '/',
|
|
'heartbeat' => 30,
|
|
'heartbeat_callback' => function () {
|
|
echo " [-] coroutine-consumer-heartbeat\n";
|
|
},
|
|
'interval' => [100, 300]
|
|
])->connect();
|
|
$channel = $client->channel();
|
|
$channel->queueDeclare($queue);
|
|
$channel->consume(function (Message $message, Channel $channel, \Bunny\AbstractClient $client) {
|
|
echo " [>] 接收到消息 ", $message->content, "\n";
|
|
},
|
|
$queue,
|
|
'',
|
|
false,
|
|
true
|
|
);
|
|
$client->run();
|
|
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
|
|
};
|
|
}
|
|
} |