feat : Proxy Remote Fail

This commit is contained in:
2025-09-07 14:18:01 +08:00
parent 32bc27596e
commit 75af9debfb
7 changed files with 463 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ use App\Service\Test\Proxy\AopService;
use App\Service\Test\Proxy\BasicSubjectService; use App\Service\Test\Proxy\BasicSubjectService;
use App\Service\Test\Proxy\DynamicProxyService; use App\Service\Test\Proxy\DynamicProxyService;
use App\Service\Test\Proxy\Payment\PaymentService; use App\Service\Test\Proxy\Payment\PaymentService;
use App\Service\Test\Proxy\RemoteService;
use App\Service\Test\Proxy\UserInfoService; use App\Service\Test\Proxy\UserInfoService;
use App\Service\Test\Proxy\UserService; use App\Service\Test\Proxy\UserService;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
@@ -60,8 +61,12 @@ class ProxyController
return (new UserService)->handle(); return (new UserService)->handle();
} }
public function remote() /**
* @return array
*/
#[RequestMapping(path: 'remote', methods: 'GET')]
public function remote(): array
{ {
return (new RemoteService)->handle();
} }
} }

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Interface\Test\Proxy;
interface OrderInterface
{
/**
* 创建订单
* @param array $data
* @return array
*/
public function createOrder(array $data): array;
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Proxy\Remote;
use App\Interface\Test\Proxy\OrderInterface;
class LocalOrderService implements OrderInterface
{
/**
* 本地订单
* @param array $data
* @return array
*/
public function createOrder(array $data): array
{
return [
'order_id' => uniqid(),
'status' => 'created',
];
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Proxy\Remote;
use App\Interface\Test\Decorator\LoggerInterface;
use App\Interface\Test\Proxy\OrderInterface;
use Hyperf\RpcClient\ProxyFactory;
use Throwable;
class RemoteOrderServiceProxy implements OrderInterface
{
/**
* @var LoggerInterface
*/
protected LoggerInterface $logger;
// public function __construct(ProxyFactory $rpcClient, LoggerInterface $logger)
// {
// $this->rpcClient = $rpcClient;
// $this->logger = $logger;
// }
public function createOrder(array $data): array
{
$data['request_id'] = uniqid();
$data['timestamp'] = time();
$this->logger->log('Sending order creation request'.json_encode($data));
try {
// $response = $this->rpcClient->__call('OrderService.createOrder',[$data]);
$this->logger->log('Order created successfully, response:'.json_encode($response));
return $response;
} catch (Throwable $exception) {
$this->logger->error('Order creation error: '.$exception->getMessage());
return [];
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Proxy;
use App\Service\Test\Proxy\Remote\LocalOrderService;
use App\Service\Test\TestBaseService;
use Hyperf\Di\Annotation\Inject;
class RemoteService extends TestBaseService
{
/**
* @var LocalOrderService
*/
#[Inject]
protected LocalOrderService $localOrderService;
/**
* @return array
*/
public function handle(): array
{
$this->localOrderService->createOrder($this->request->all());
return $this->return->success();
}
}

View File

@@ -31,6 +31,7 @@
"hyperf/model-cache": "~3.1.0", "hyperf/model-cache": "~3.1.0",
"hyperf/process": "~3.1.0", "hyperf/process": "~3.1.0",
"hyperf/redis": "~3.1.0", "hyperf/redis": "~3.1.0",
"hyperf/rpc-client": "^3.1",
"hyperf/tracer": "~3.1.0" "hyperf/tracer": "~3.1.0"
}, },
"require-dev": { "require-dev": {

327
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "4ac3b7f3d4fc837bc272d5727a863971", "content-hash": "03d201d24ea04aa8cfada8967ab9b056",
"packages": [ "packages": [
{ {
"name": "carbonphp/carbon-doctrine-types", "name": "carbonphp/carbon-doctrine-types",
@@ -2744,6 +2744,71 @@
], ],
"time": "2025-06-30T01:39:01+00:00" "time": "2025-06-30T01:39:01+00:00"
}, },
{
"name": "hyperf/load-balancer",
"version": "v3.1.42",
"source": {
"type": "git",
"url": "https://github.com/hyperf/load-balancer.git",
"reference": "13d23eae71f917df4df54f7439076360dc5f9cc0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hyperf/load-balancer/zipball/13d23eae71f917df4df54f7439076360dc5f9cc0",
"reference": "13d23eae71f917df4df54f7439076360dc5f9cc0",
"shasum": ""
},
"require": {
"hyperf/coordinator": "~3.1.0",
"hyperf/coroutine": "~3.1.0",
"markrogoyski/math-php": "^2.0",
"php": ">=8.1",
"psr/log": "^1.0 || ^2.0 || ^3.0"
},
"type": "library",
"extra": {
"hyperf": {
"config": "Hyperf\\LoadBalancer\\ConfigProvider"
},
"branch-alias": {
"dev-master": "3.1-dev"
}
},
"autoload": {
"psr-4": {
"Hyperf\\LoadBalancer\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "A load balancer library for Hyperf.",
"homepage": "https://hyperf.io",
"keywords": [
"hyperf",
"load-balancer",
"php",
"swoole"
],
"support": {
"docs": "https://hyperf.wiki",
"issues": "https://github.com/hyperf/hyperf/issues",
"pull-request": "https://github.com/hyperf/hyperf/pulls",
"source": "https://github.com/hyperf/hyperf"
},
"funding": [
{
"url": "https://hyperf.wiki/#/zh-cn/donate",
"type": "custom"
},
{
"url": "https://opencollective.com/hyperf",
"type": "open_collective"
}
],
"time": "2024-09-25T02:54:12+00:00"
},
{ {
"name": "hyperf/logger", "name": "hyperf/logger",
"version": "v3.1.57", "version": "v3.1.57",
@@ -3344,6 +3409,149 @@
], ],
"time": "2025-07-03T04:20:32+00:00" "time": "2025-07-03T04:20:32+00:00"
}, },
{
"name": "hyperf/rpc",
"version": "v3.1.57",
"source": {
"type": "git",
"url": "https://github.com/hyperf/rpc.git",
"reference": "1c81cd46be8d1926096cf333849add07e755ced3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hyperf/rpc/zipball/1c81cd46be8d1926096cf333849add07e755ced3",
"reference": "1c81cd46be8d1926096cf333849add07e755ced3",
"shasum": ""
},
"require": {
"hyperf/codec": "~3.1.0",
"hyperf/collection": "~3.1.0",
"hyperf/context": "~3.1.0",
"hyperf/contract": "~3.1.0",
"hyperf/stringable": "~3.1.0",
"hyperf/support": "~3.1.0",
"jetbrains/phpstorm-attributes": "^1.0",
"php": ">=8.1"
},
"type": "library",
"extra": {
"hyperf": [],
"branch-alias": {
"dev-master": "3.1-dev"
}
},
"autoload": {
"psr-4": {
"Hyperf\\Rpc\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "A rpc basic library for Hyperf.",
"homepage": "https://hyperf.io",
"keywords": [
"hyperf",
"php",
"rpc",
"swoole"
],
"support": {
"docs": "https://hyperf.wiki",
"issues": "https://github.com/hyperf/hyperf/issues",
"pull-request": "https://github.com/hyperf/hyperf/pulls",
"source": "https://github.com/hyperf/hyperf"
},
"funding": [
{
"url": "https://hyperf.wiki/#/zh-cn/donate",
"type": "custom"
},
{
"url": "https://opencollective.com/hyperf",
"type": "open_collective"
}
],
"time": "2025-06-06T02:41:30+00:00"
},
{
"name": "hyperf/rpc-client",
"version": "v3.1.57",
"source": {
"type": "git",
"url": "https://github.com/hyperf/rpc-client.git",
"reference": "ff9299aed4aebd3c6aeb871e3e5482dfa262bb7d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hyperf/rpc-client/zipball/ff9299aed4aebd3c6aeb871e3e5482dfa262bb7d",
"reference": "ff9299aed4aebd3c6aeb871e3e5482dfa262bb7d",
"shasum": ""
},
"require": {
"hyperf/code-parser": "~3.1.0",
"hyperf/collection": "~3.1.0",
"hyperf/contract": "~3.1.0",
"hyperf/coroutine": "~3.1.0",
"hyperf/load-balancer": "~3.1.0",
"hyperf/rpc": "~3.1.0",
"hyperf/support": "~3.1.0",
"jetbrains/phpstorm-attributes": "^1.0",
"php": ">=8.1",
"psr/container": "^1.0 || ^2.0"
},
"suggest": {
"hyperf/di": "For better container experience.",
"hyperf/pool": "Required to use connection pool.",
"hyperf/service-governance": "Required to fetch the nodes info from service governance."
},
"type": "library",
"extra": {
"hyperf": {
"config": "Hyperf\\RpcClient\\ConfigProvider"
},
"branch-alias": {
"dev-master": "3.1-dev"
}
},
"autoload": {
"psr-4": {
"Hyperf\\RpcClient\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "An abstract rpc server component for Hyperf.",
"homepage": "https://hyperf.io",
"keywords": [
"hyperf",
"json-rpc",
"php",
"rpc",
"rpc-client",
"swoole"
],
"support": {
"docs": "https://hyperf.wiki",
"issues": "https://github.com/hyperf/hyperf/issues",
"pull-request": "https://github.com/hyperf/hyperf/pulls",
"source": "https://github.com/hyperf/hyperf"
},
"funding": [
{
"url": "https://hyperf.wiki/#/zh-cn/donate",
"type": "custom"
},
{
"url": "https://opencollective.com/hyperf",
"type": "open_collective"
}
],
"time": "2025-06-06T02:41:30+00:00"
},
{ {
"name": "hyperf/serializer", "name": "hyperf/serializer",
"version": "v3.1.42", "version": "v3.1.42",
@@ -3886,6 +4094,48 @@
], ],
"time": "2023-11-03T22:38:29+00:00" "time": "2023-11-03T22:38:29+00:00"
}, },
{
"name": "jetbrains/phpstorm-attributes",
"version": "1.2",
"source": {
"type": "git",
"url": "https://github.com/JetBrains/phpstorm-attributes.git",
"reference": "64de815a4509c29e00d5e3474087fd24c171afc2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/JetBrains/phpstorm-attributes/zipball/64de815a4509c29e00d5e3474087fd24c171afc2",
"reference": "64de815a4509c29e00d5e3474087fd24c171afc2",
"shasum": ""
},
"type": "library",
"autoload": {
"psr-4": {
"JetBrains\\PhpStorm\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "JetBrains",
"homepage": "https://www.jetbrains.com"
}
],
"description": "PhpStorm specific attributes",
"keywords": [
"attributes",
"jetbrains",
"phpstorm"
],
"support": {
"issues": "https://youtrack.jetbrains.com/newIssue?project=WI",
"source": "https://github.com/JetBrains/phpstorm-attributes/tree/1.2"
},
"time": "2024-10-11T10:46:19+00:00"
},
{ {
"name": "laminas/laminas-mime", "name": "laminas/laminas-mime",
"version": "2.12.0", "version": "2.12.0",
@@ -4007,6 +4257,81 @@
], ],
"time": "2024-10-29T13:46:07+00:00" "time": "2024-10-29T13:46:07+00:00"
}, },
{
"name": "markrogoyski/math-php",
"version": "v2.11.0",
"source": {
"type": "git",
"url": "https://github.com/markrogoyski/math-php.git",
"reference": "ae499f31513821a62f3d2fb8c6f0d3a333e8b591"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/markrogoyski/math-php/zipball/ae499f31513821a62f3d2fb8c6f0d3a333e8b591",
"reference": "ae499f31513821a62f3d2fb8c6f0d3a333e8b591",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": ">=7.2.0"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phploc/phploc": "*",
"phpmd/phpmd": "^2.6",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "3.*"
},
"type": "library",
"autoload": {
"psr-4": {
"MathPHP\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Rogoyski",
"email": "mark@rogoyski.com",
"homepage": "https://github.com/markrogoyski",
"role": "Lead developer"
},
{
"name": "Kevin Nowaczyk",
"homepage": "https://github.com/Beakerboy",
"role": "Developer"
},
{
"name": "MathPHP Community of Contributors",
"homepage": "https://github.com/markrogoyski/math-php/graphs/contributors"
}
],
"description": "Math Library for PHP. Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra",
"homepage": "https://github.com/markrogoyski/math-php/",
"keywords": [
"algebra",
"combinatorics",
"distributions",
"linear algebra",
"math",
"mathematics",
"matrix",
"numerical analysis",
"probability",
"regressions",
"statistics"
],
"support": {
"issues": "https://github.com/markrogoyski/math-php/issues",
"source": "https://github.com/markrogoyski/math-php/tree/v2.11.0"
},
"time": "2025-01-26T20:16:06+00:00"
},
{ {
"name": "monolog/monolog", "name": "monolog/monolog",
"version": "3.9.0", "version": "3.9.0",