proto文件在实际开发中较为麻烦,引入Protobuf-net.Grpc优化开发过程
1.创建类库 ProtobufNet

微服务-基于Grpc的进程通信-Protobuf-net.Grpc(4-3)

(1)创建两个实体对象 ProtobufRequestProtobufResponse
通过标签DataContractDataMember来约定请求和返回对象

 微服务-基于Grpc的进程通信-Protobuf-net.Grpc(4-3)

 微服务-基于Grpc的进程通信-Protobuf-net.Grpc(4-3)

注:Order对应的序号不能重复
 
(2)创建接口层Iprotobuf.cs和实现层protobufService.cs
通过标签ServiceContract来约定接口名称

 微服务-基于Grpc的进程通信-Protobuf-net.Grpc(4-3)

 微服务-基于Grpc的进程通信-Protobuf-net.Grpc(4-3)

2.修改Server端
添加Nuget包 protobuf-net.Grpc.AspNetCore
添加对类库"ProtobufNet"的引用

 微服务-基于Grpc的进程通信-Protobuf-net.Grpc(4-3)

在Startup.cs中修改配置:

微服务-基于Grpc的进程通信-Protobuf-net.Grpc(4-3)
 
注册Grpc服务 protobufService.cs

 微服务-基于Grpc的进程通信-Protobuf-net.Grpc(4-3)

3.修改Client端
添加Nuget包 protobuf-net.Grpc.ClientFactory
连接grpc服务端并调用

 微服务-基于Grpc的进程通信-Protobuf-net.Grpc(4-3)

 

4.结果

 微服务-基于Grpc的进程通信-Protobuf-net.Grpc(4-3)

 

以上,仅用于学习和总结!

附源码:
链接:https://pan.baidu.com/s/1rEV3MqNnIJF25rRr4V0PLg
提取码:x1ah
 
 
参考文档:

 

相关文章:

  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-06-15
  • 2022-12-23
相关资源
相似解决方案