diff --git a/app/process/RabbConsumApplySmsTemp.php b/app/process/RabbConsumApplySmsTemp.php new file mode 100644 index 0000000..6a7fc39 --- /dev/null +++ b/app/process/RabbConsumApplySmsTemp.php @@ -0,0 +1,49 @@ +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"; + }; + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index be7ae01..108d2bc 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,8 @@ "php-amqplib/php-amqplib": "^3.6", "alibabacloud/dysmsapi-20170525": "^4.2", "alibabacloud/tea": "^3.2", - "alibabacloud/tea-utils": "^0.2.21" + "alibabacloud/tea-utils": "^0.2.21", + "workerman/rabbitmq": "^2.1" }, "suggest": { "ext-event": "For better performance. " diff --git a/composer.lock b/composer.lock index 74c0637..fa04d2e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "88c1a3313c5a2650ded93bc53da2caa5", + "content-hash": "dcf84a121e3d44c265df9714baaca000", "packages": [ { "name": "adbario/php-dot-notation", @@ -489,6 +489,77 @@ }, "time": "2024-07-05T06:05:54+00:00" }, + { + "name": "bunny/bunny", + "version": "v0.5.6", + "source": { + "type": "git", + "url": "https://github.com/jakubkulhan/bunny.git", + "reference": "2714c26466d061e1236dbbe9b892324f8be80d63" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jakubkulhan/bunny/zipball/2714c26466d061e1236dbbe9b892324f8be80d63", + "reference": "2714c26466d061e1236dbbe9b892324f8be80d63", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.1 || ^8.0", + "react/event-loop": "^1.0 || ^0.5 || ^0.4", + "react/promise": "~2.2" + }, + "require-dev": { + "ext-pcntl": "*", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.5 || ^7.5.20", + "symfony/process": "^6.1 || ^4.4" + }, + "suggest": { + "ext-pcntl": "For using synchronous AMQP/RabbitMQ client" + }, + "type": "library", + "autoload": { + "psr-4": { + "Bunny\\": "src/Bunny/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jakub Kulhan", + "email": "jakub.kulhan@gmail.com" + } + ], + "description": "Performant pure-PHP AMQP (RabbitMQ) sync/async (ReactPHP) library", + "keywords": [ + "AMQP", + "bunny", + "exchange", + "message", + "messaging", + "queue", + "queueing", + "rabbit", + "rabbitmq", + "react", + "react-php", + "reactphp" + ], + "support": { + "issues": "https://github.com/jakubkulhan/bunny/issues", + "source": "https://github.com/jakubkulhan/bunny/tree/v0.5.6" + }, + "time": "2025-05-22T09:49:34+00:00" + }, { "name": "carbonphp/carbon-doctrine-types", "version": "3.2.0", @@ -3062,6 +3133,162 @@ }, "time": "2019-03-08T08:55:37+00:00" }, + { + "name": "react/event-loop", + "version": "v1.5.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/event-loop.git", + "reference": "bbe0bd8c51ffc05ee43f1729087ed3bdf7d53354" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/event-loop/zipball/bbe0bd8c51ffc05ee43f1729087ed3bdf7d53354", + "reference": "bbe0bd8c51ffc05ee43f1729087ed3bdf7d53354", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" + }, + "suggest": { + "ext-pcntl": "For signal handling support when using the StreamSelectLoop" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\EventLoop\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "ReactPHP's core reactor event loop that libraries can use for evented I/O.", + "keywords": [ + "asynchronous", + "event-loop" + ], + "support": { + "issues": "https://github.com/reactphp/event-loop/issues", + "source": "https://github.com/reactphp/event-loop/tree/v1.5.0" + }, + "funding": [ + { + "url": "https://opencollective.com/reactphp", + "type": "open_collective" + } + ], + "time": "2023-11-13T13:48:05+00:00" + }, + { + "name": "react/promise", + "version": "v2.11.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/promise.git", + "reference": "1a8460931ea36dc5c76838fec5734d55c88c6831" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/promise/zipball/1a8460931ea36dc5c76838fec5734d55c88c6831", + "reference": "1a8460931ea36dc5c76838fec5734d55c88c6831", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "React\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "keywords": [ + "promise", + "promises" + ], + "support": { + "issues": "https://github.com/reactphp/promise/issues", + "source": "https://github.com/reactphp/promise/tree/v2.11.0" + }, + "funding": [ + { + "url": "https://opencollective.com/reactphp", + "type": "open_collective" + } + ], + "time": "2023-11-16T16:16:50+00:00" + }, { "name": "symfony/cache", "version": "v6.4.23", @@ -5402,6 +5629,78 @@ ], "time": "2023-12-08T00:54:08+00:00" }, + { + "name": "workerman/rabbitmq", + "version": "v2.1.1", + "source": { + "type": "git", + "url": "https://github.com/walkor/rabbitmq.git", + "reference": "8f3d1b0b8c71326fb418846ef9df42b4c59cb69c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/walkor/rabbitmq/zipball/8f3d1b0b8c71326fb418846ef9df42b4c59cb69c", + "reference": "8f3d1b0b8c71326fb418846ef9df42b4c59cb69c", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "bunny/bunny": "^0.5", + "php": "^8.1", + "psr/log": "^1.0 || ^2.0 || ^3.0", + "workerman/webman-framework": "^2.1 || dev-master", + "workerman/workerman": "^5.0" + }, + "require-dev": { + "revolt/event-loop": "^1.0", + "symfony/var-dumper": "^6.0 | ^7.0" + }, + "suggest": { + "workerman/coroutine": "For supporting Coroutine. " + }, + "type": "library", + "autoload": { + "psr-4": { + "Workerman\\RabbitMQ\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "walkor", + "email": "walkor@workerman.net", + "homepage": "http://www.workerman.net", + "role": "Developer" + }, + { + "name": "chaz6chez", + "email": "chaz6chez1993@outlook.com", + "role": "Developer" + } + ], + "description": "Asynchronous rabbitmq client for PHP based on workerman.", + "homepage": "https://www.workerman.net", + "keywords": [ + "AMQP", + "rabbitmq client" + ], + "support": { + "email": "walkor@workerman.net", + "forum": "http://wenda.workerman.net/", + "issues": "https://github.com/walkor/rabbitmq/issues", + "source": "https://github.com/walkor/rabbitmq", + "wiki": "http://doc.workerman.net/" + }, + "time": "2025-04-27T03:59:08+00:00" + }, { "name": "workerman/redis", "version": "v2.0.4", diff --git a/config/process.php b/config/process.php index 59a642c..fb8b6cb 100644 --- a/config/process.php +++ b/config/process.php @@ -13,6 +13,7 @@ */ use app\process\MessagePushTask; +use app\process\RabbConsumApplySmsTemp; use support\Log; use support\Request; use app\process\Http; @@ -68,5 +69,9 @@ return [ // 定时任务/查询短信发送状态/查询模版审核状态/按天插入过期时间 'QuerySmsStatus' => [ 'handler' => MessagePushTask::class + ], + // rabbitmq 消费者 + 'RabbitmqConsum' => [ + 'handler' => RabbConsumApplySmsTemp::class ] ];