tinywan\rpc组件

This commit is contained in:
hgc 2024-12-26 21:13:49 +08:00
parent d1713a5189
commit f145391b52
5 changed files with 181 additions and 2 deletions

View File

@ -40,7 +40,8 @@
"illuminate/redis": "^10.48",
"symfony/var-dumper": "^6.4",
"webman/think-orm": "^1.1",
"phpoffice/phpspreadsheet": "^3.6"
"phpoffice/phpspreadsheet": "^3.6",
"tinywan/rpc": "^1.3"
},
"suggest": {
"ext-event": "For better performance. "

103
composer.lock generated
View File

@ -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": "69fc720415852f55d5319c4ab078fb79",
"content-hash": "55aa2739027c5188b7b150b785715692",
"packages": [
{
"name": "brick/math",
@ -3663,6 +3663,107 @@
],
"time": "2024-11-08T15:28:48+00:00"
},
{
"name": "tinywan/exception-handler",
"version": "v1.5.4",
"source": {
"type": "git",
"url": "https://github.com/Tinywan/webman-exception.git",
"reference": "19b58b0e3c6927fa0726c0896364275329ab52d5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Tinywan/webman-exception/zipball/19b58b0e3c6927fa0726c0896364275329ab52d5",
"reference": "19b58b0e3c6927fa0726c0896364275329ab52d5",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": ">=7.4",
"workerman/webman-framework": "^1.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.6",
"phpstan/phpstan": "^1.4",
"tinywan/jwt": "^1.2",
"tinywan/storage": "^0.2.2",
"tinywan/validate": "^1.0",
"webman/think-orm": "^1.1",
"workerman/webman": "^1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Tinywan\\ExceptionHandler\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "webman exception handler plugin",
"support": {
"issues": "https://github.com/Tinywan/webman-exception/issues",
"source": "https://github.com/Tinywan/webman-exception/tree/v1.5.4"
},
"time": "2024-07-13T05:00:19+00:00"
},
{
"name": "tinywan/rpc",
"version": "v1.3.0",
"source": {
"type": "git",
"url": "https://github.com/Tinywan/webman-rpc.git",
"reference": "5bad7989a88f877a2b1579f862e7894533368d6a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Tinywan/webman-rpc/zipball/5bad7989a88f877a2b1579f862e7894533368d6a",
"reference": "5bad7989a88f877a2b1579f862e7894533368d6a",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": ">=7.4",
"tinywan/exception-handler": "^1.5",
"workerman/webman-framework": "^1.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.6",
"phpstan/phpstan": "^1.4",
"workerman/webman": "^1.0"
},
"type": "library",
"autoload": {
"files": [
"src/function.php"
],
"psr-4": {
"Tinywan\\Rpc\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Tinywan",
"email": "756684177@qq.com"
}
],
"description": "simple rpc service for webman plugin",
"keywords": [
"plugin",
"rpc",
"webman"
],
"support": {
"issues": "https://github.com/Tinywan/webman-rpc/issues",
"source": "https://github.com/Tinywan/webman-rpc/tree/v1.3.0"
},
"time": "2024-08-16T06:46:51+00:00"
},
{
"name": "topthink/think-helper",
"version": "v3.1.10",

View File

@ -0,0 +1,59 @@
<?php
return [
'enable' => true,
// 错误异常配置
'exception_handler' => [
// 不需要记录错误日志
'dont_report' => [
Tinywan\ExceptionHandler\Exception\BadRequestHttpException::class,
Tinywan\ExceptionHandler\Exception\UnauthorizedHttpException::class,
Tinywan\ExceptionHandler\Exception\ForbiddenHttpException::class,
Tinywan\ExceptionHandler\Exception\NotFoundHttpException::class,
Tinywan\ExceptionHandler\Exception\RouteNotFoundException::class,
Tinywan\ExceptionHandler\Exception\TooManyRequestsHttpException::class,
Tinywan\ExceptionHandler\Exception\ServerErrorHttpException::class,
Tinywan\Validate\Exception\ValidateException::class,
Tinywan\Jwt\Exception\JwtTokenException::class
],
// 自定义HTTP状态码
'status' => [
'validate' => 400, // 验证器异常
'jwt_token' => 401, // 认证失败
'jwt_token_expired' => 401, // 访问令牌过期
'jwt_refresh_token_expired' => 402, // 刷新令牌过期
'server_error' => 500, // 服务器内部错误
'server_error_is_response' => false, // 是否响应服务器内部错误
'type_error' => 400, // 参数类型错误码
'type_error_is_response' => false, // 参数类型与预期声明的参数类型不匹配
],
// 自定义响应消息
'body' => [
'code' => 0,
'msg' => '服务器内部异常',
'data' => null
],
// 事件event 与 webman/event 存在冲突event 重命名为 event_trigger
'event_trigger' => [
'enable' => false,
// 钉钉机器人
'dingtalk' => [
'accessToken' => 'xxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxx',
'title' => '钉钉机器人异常通知',
]
],
/** 异常报警域名标题 */
'domain' => [
'dev' => 'dev-api.tinywan.com', // 开发环境
'test' => 'test-api.tinywan.com', // 测试环境
'pre' => 'pre-api.tinywan.com', // 预发环境
'prod' => 'api.tinywan.com', // 生产环境
],
/** 是否生产环境 。可以通过配置文件或者数据库读取返回 egreturn config('app.env') === 'prod';*/
'is_prod_env' => function () {
return false;
},
],
];

View File

@ -0,0 +1,9 @@
<?php
return [
'enable' => true,
'server' => [
'namespace'=> 'service\\', // 自定义服务命名空间
'listen_text_address' => 'text://0.0.0.0:9512', // 自定义Text协议地址
],
];

View File

@ -0,0 +1,9 @@
<?php
return [
// 自定义Text协议
'text.protocol' => [
'handler'=> \Tinywan\Rpc\Protocol\RpcTextProtocol::class,
'listen' => config('plugin.tinywan.rpc.app.server.listen_text_address'),
'count' => 10, // 根据配置文件调整
]
];