chllen/hyperf-grpc-client

There is no license information available for the latest version (v1.0.0-alpha) of this package.

A grpc client component for Hyperf.

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

This package is auto-updated.

Last update: 2024-04-20 08:45:23 UTC


README

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

#配置 添加配置文件 etcd.php command: 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']
        );
    }
}