wjy / rpc-helper
v0.1.2
2024-08-29 04:09 UTC
Requires
- php: >=8.1
- hyperf/di: >=v3.1.0
- hyperf/event: ^3.1
- hyperf/framework: >=v3.1.0
- hyperf/http-server: >=v3.1.0
Suggests
- swow/swow: Required to create swow components.
This package is not auto-updated.
Last update: 2025-01-16 06:21:42 UTC
README
安装
composer require wjy/rpc-helper
使用
#[RpcClient]
自动配置服务消费者,省去配置services.consumers
步骤
#[RpcClient(registerCenter: 'nacos')] class CalculatorServiceClient extends AbstractServiceClient implements CalculatorServiceInterface { protected string $serviceName = 'CalculatorService'; // ... }
指定nacos地址, 默认使用services.php
配置的nacos
#[RpcClient(registerCenter: 'nacos', address: 'http://localhost:8848')]
如果不使用配置中心
#[RpcClient(nodes: ['localhost:9502'])]
微服务代理接口
#[RpcController(prefix: '/calculator')] // prefix默认为类名首字母小写 class GoodsService implements GoodsServiceInterface { #[RpcMapping(method: 'get')] // path默认是方法名 接口: /calculator/add public function add($a, $b) { return $a + $b; } #[RpcMapping(path: 'minus', method: 'get')] // 指定path地址 接口: /calculator/add public function minus($a, $b) { return $a + $b; } }