crayoon / hyperf-grpc
hyperf grpc extend
Installs: 1 637
Dependents: 0
Suggesters: 0
Security: 0
Stars: 24
Watchers: 1
Forks: 2
Open Issues: 1
Requires
- php: >=8.0
- hyperf/di: 3.0.*
- hyperf/grpc-server: ^3.0
- hyperf/http-server: ^3.0
- hyperf/service-governance: ^3.0
- hyperf/service-governance-consul: ^3.0
- hyperf/service-governance-nacos: ^3.0
- hyperf/tracer: ^3.0
- hyperf/utils: ^3.0
- jonahgeorge/jaeger-client-php: ^1.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- mockery/mockery: ^1.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: >=7.0
- swoole/ide-helper: ^4.5
README
Hyperf Grpc 服务插件,协助完成grpc服务注册、服务链路追踪、服务健康、服务反射等
使用教程 https://learnku.com/articles/75681 如果有帮助到您的话,还请给个星哦
请先阅读hyperf文档grpc服务一节 https://hyperf.wiki/3.0/#/zh-cn/grpc
Update
[2.x]
- 服务处理重写,支持GRPC全模式(一元模式、客户端流模式、服务端流模式、双向流模式)
[1.x]
- 重构服务反射,提升速度
- TracerDriver 默认配置调整为Noop类型
- 服务注册优化异常时跳过
- 增加支持 Grpc Streaming
- 增积支持 GrpcHealth Watch Streaming模式
快速开始
引入
composer require crayoon/hyperf-grpc dev-2.0-alpha
生成配置文件
php bin/hyperf.php vendor:publish crayoon/hyperf-grpc
配置
修改 config/autoload/annotations.php
return [ 'scan' => [ 'paths' => [ BASE_PATH . '/app', ], 'ignore_annotations' => [ 'mixin', ], 'class_map' => [ \Google\Protobuf\Internal\DescriptorPool::class => BASE_PATH.'/vendor/crayoon/hyperf-grpc/class_map/Protobuf/DescriptorPool.php' ] ] ];
修改 config/autoload/server.php
'servers' => [ [ 'name' => 'grpc', 'type' => Server::SERVER_BASE, 'host' => '0.0.0.0', 'port' => 9501, 'sock_type' => SWOOLE_SOCK_TCP, 'callbacks' => [ Event::ON_RECEIVE => [\Crayoon\HyperfGrpc\Server\StreamServer::class, 'onReceive'] ], ], ... ],
流模式使用
// config/routes.php // 路由使用助手类注册 GrpcHelper::RegisterRoutes(function () { // 在此处添加路由 Router::addGroup('/goods.v1.Goods', function () { Router::post('/info', [\App\Controller\Grpc\GoodsController::class, "info"]); ... }); ... }, 'grpc', [], true);