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\DynamicProxyService;
use App\Service\Test\Proxy\Payment\PaymentService;
use App\Service\Test\Proxy\RemoteService;
use App\Service\Test\Proxy\UserInfoService;
use App\Service\Test\Proxy\UserService;
use Hyperf\HttpServer\Annotation\Controller;
@@ -60,8 +61,12 @@ class ProxyController
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();
}
}