开启协程

This commit is contained in:
ASUS 2025-11-05 17:00:36 +08:00
parent 1555d77ae9
commit 24def09ea4
3 changed files with 3 additions and 52 deletions

View File

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

View File

@ -22,6 +22,7 @@ return [
'worker' => [ 'worker' => [
'handler' => BusinessWorker::class, 'handler' => BusinessWorker::class,
'count' => cpu_count()*2, 'count' => cpu_count()*2,
'eventLoop' => \Workerman\Events\Swoole::class,
'constructor' => ['config' => [ 'constructor' => ['config' => [
'eventHandler' => plugin\webman\gateway\Events::class, 'eventHandler' => plugin\webman\gateway\Events::class,
'name' => 'ChatBusinessWorker', 'name' => 'ChatBusinessWorker',

View File

@ -13,7 +13,6 @@
*/ */
use app\process\MessagePushTask; use app\process\MessagePushTask;
use app\process\RabbConsumApplySmsTemp;
use support\Log; use support\Log;
use support\Request; use support\Request;
use app\process\Http; use app\process\Http;
@ -28,8 +27,8 @@ return [
'user' => '', 'user' => '',
'group' => '', 'group' => '',
'reusePort' => false, 'reusePort' => false,
'eventLoop' => '', // 'eventLoop' => '',
// 'eventLoop' => \Workerman\Events\Swoole::class, 'eventLoop' => \Workerman\Events\Swoole::class,
'context' => [], 'context' => [],
'constructor' => [ 'constructor' => [
'requestClass' => Request::class, 'requestClass' => Request::class,