alicfeng / service-client
A client for remote calling microservice communication
Installs: 19
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/alicfeng/service-client
Requires
- php: ^7.0|^8.0
- ext-json: *
- friendsofphp/php-cs-fixer: ^2.18
Requires (Dev)
- mockery/mockery: ^1.4.2
- nunomaduro/collision: ^5.0
- phpunit/phpunit: ^9.3.3
README
服务客户端
一款远程调用微服务通讯的客户端
支持多种通讯协议的远程调用客户端,安装一个客户端可配置灵活调用多个服务
🚀 安装配置
standard
composer require alicfeng/service-client -vvv
Laravel
php artisan vendor:publish --provider="Samego\Client\ServiceProvider\ServiceClientProvider"
✨ 支持特性
-
Http
-
ICE
-
Grpc
☛ 快速使用
<?php
return [
'arrangement' => [
'success_code' => 1000,
],
// 协议驱动 HTTP
'http' => [
// 路由列表
'routes' => [
// 服务路由 服务名称.路由别名
'user.profile' => [
'uri' => '/api/user',
'method' => 'GET',
'headers' => [
],
],
],
// 服务分组 配置每组服务通用配置
'groups' => [
'user' => [
'timeout' => 60,
'base_uri' => env('SERVICE_CLIENT_USER_SERVER_BASE_URI'),
'verify' => env('SERVICE_CLIENT_USER_SERVER_VERIFY', false),
'headers' => [
],
],
],
],
];
use Samego\Client\Facades\ServiceHttpClient;
// 简单请求
ServiceHttpClient::service('user.profile')->request();
// 复杂请求
ServiceHttpClient::service('user.profile')->package(['name'=>'samego'])->header(['Auth'=>'token'])->uri('api/user/profile')->request();
✅组件建议
- 对于
Http提供服务的建议使用 laravel-response 作为配套响应组件