chllen/hyperf-grpc-client

该软件包最新版本(v1.0.0-alpha)没有可用的许可证信息。

Hyperf 的 gRPC 客户端组件。

v1.0.0-alpha 2023-02-18 14:33 UTC

This package is auto-updated.

Last update: 2024-09-20 09:41:53 UTC


README

该组件基于hyperf框架,构建实现服务发现的gRPC客户端,我们实现了以etcd为服务中心的组件支持, 目前仅支持对接go-micro。

#配置 添加配置文件 etcd.php 命令: php bin/hyperf.php vendor:publish chllen/hyperf-grpc-client

return [
    'uri' => 'http://127.0.0.1:2379',
    'version' => 'v3beta',
    'retry_interval' => 5,
    'path_prefix' => '/micro/registry',
    'framework' => 'go-micro',
    'options' => [
        'timeout' => 10, 
    ],
];

#使用 封装类Chllen\HyperfGrpcClient\GrpcClient继承于\Hyperf\GrpcClient\BaseClient ,根据 .proto 文件中的定义, 按需扩展

use Chllen\HyperfGrpcClient\GrpcClient

class OrderClient extends GrpcClient
{
    public function create(Order $order)
    {
        return $this->_simpleRequest(
            '/orderService/create',
            $order,
            [OrderReply::class, 'decode']
        );
    }
}