alicfeng/service-client

A client for remote calling microservice communication

1.0.0 2021-05-19 02:26 UTC

This package is auto-updated.

Last update: 2024-05-11 11:43:01 UTC


README

一款远程调用微服务通讯的客户端
支持多种通讯协议的远程调用客户端,安装一个客户端可配置灵活调用多个服务

Build Status Latest Stable Version Total Downloads License

🚀 安装配置

  • 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();

✅组件建议

  1. 对于 Http 提供服务的建议使用 laravel-response 作为配套响应组件