基于Ocelot的gRpcHttp网关

什么是gRpcHttp网关

通俗的讲就是将gRpc提供的服务以rest api的形式提供出去,不需要再单独的写一个webapi去
做这件事。

gRpcHttp网关好处
减少不必要代码,减少中间层提高通讯效率。

以前可能是这样
基于Ocelot的gRpcHttp网关
文章图片

用了gRpc网关后是这样
基于Ocelot的gRpcHttp网关
文章图片

gRpcHttp网关提供哪些功能
  • 可以直接加载proto生成的dll文件
  • 可以只需要proto文件,自动解析出proto文件所提供的model和service
  • 支持header转发
  • 支持gRpc的四种模式
  • 支持gRpc中间件
  • 支持swagger(开发中)
  • 支持proto和dll文件动态新增,不需要重启网关
Getting Started
  • git clone https://github.com/BuiltCloud/Ocelot.GrpcHttpGateway.git
  • cd Ocelot.GrpcHttpGateway/src
  • cd samples\OcelotGateway and dotnet run
  • cd samples\Examples.GrpcServer and dotnet run
  • copy Examples.GrpcModels.dll to samples\OcelotGateway\bin\Debug\netcoreapp2.1\plugins
  • curl http://localhost:5000/grpc/PLAYERSEARCH/SEARCHTEAM
  • curl http://localhost:5000/grpc/PLAYERSEARCH/SearchPlayer_ServerStream
  • curl http://localhost:5000/grpc/PLAYERSEARCH/SearchPlayer_ClientStream
  • curl http://localhost:5000/grpc/PLAYERSEARCH/SearchPlayer_DuplexStream
  • curl http://localhost:5000/srv 查看当前服务和方法
你还可以复制.proto文件到Examples.GrpcModels.dll to samples\OcelotGateway\bin\Debug\netcoreapp2.1\protos目录
查看http://localhost:5000/srv变化
Github https://github.com/BuiltCloud/Ocelot.GrpcHttpGateway 相关文章:
  • AspNetCore中使用Ocelot之 IdentityServer4
  • Ocelot-基于.NET Core的开源网关实现
  • .NET Core微服务之基于Ocelot+IdentityServer实现统一验证与授权
  • Swagger如何访问Ocelot中带权限验证的API
  • Ocelot.JwtAuthorize:一个基于网关的Jwt验证包
  • .NET Core微服务之基于Ocelot实现API网关服务
  • .NET Core微服务之基于Ocelot实现API网关服务(续)
  • .NET微服务体系结构中为什么使用Ocelot实现API网关
  • Ocelot简易教程(一)之Ocelot是什么
  • Ocelot简易教程(二)之快速开始1
  • Ocelot简易教程(二)之快速开始2
  • Ocelot简易教程(三)之主要特性及路由详解
  • Ocelot简易教程(四)之请求聚合以及服务发现

原文地址: https://www.cnblogs.com/kingreatwill/p/9722963.html

.NET社区新闻,深度好文,欢迎访问公众号文章汇总 http://www.csharpkit.com

【基于Ocelot的gRpcHttp网关】基于Ocelot的gRpcHttp网关
文章图片

    推荐阅读