开启协程
This commit is contained in:
parent
1555d77ae9
commit
24def09ea4
|
|
@ -1,49 +0,0 @@
|
|||
<?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";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ return [
|
|||
'worker' => [
|
||||
'handler' => BusinessWorker::class,
|
||||
'count' => cpu_count()*2,
|
||||
'eventLoop' => \Workerman\Events\Swoole::class,
|
||||
'constructor' => ['config' => [
|
||||
'eventHandler' => plugin\webman\gateway\Events::class,
|
||||
'name' => 'ChatBusinessWorker',
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
*/
|
||||
|
||||
use app\process\MessagePushTask;
|
||||
use app\process\RabbConsumApplySmsTemp;
|
||||
use support\Log;
|
||||
use support\Request;
|
||||
use app\process\Http;
|
||||
|
|
@ -28,8 +27,8 @@ return [
|
|||
'user' => '',
|
||||
'group' => '',
|
||||
'reusePort' => false,
|
||||
'eventLoop' => '',
|
||||
// 'eventLoop' => \Workerman\Events\Swoole::class,
|
||||
// 'eventLoop' => '',
|
||||
'eventLoop' => \Workerman\Events\Swoole::class,
|
||||
'context' => [],
|
||||
'constructor' => [
|
||||
'requestClass' => Request::class,
|
||||
|
|
|
|||
Loading…
Reference in New Issue