一 什么是grpc json
google出了一款分布式通信框架:grpc。我想这也不是新的东西了,在13年的一个项目中,用在了数据层和业务端之间的通信上,当时并无以为怎么样,由于wcf很轻松的也能够能够实现哪些功能。可是想在想想,确实在某些场合,grpc比wcf要更好一点。第一就是比wcf要轻量级的多,第二,跨平台,他出了一款协议Protocol Buffers,来定义接口,而后使用工具去生成不一样 的语言代码。而wcf咱们也知道,跨平台使用soap协议,基于http,坏处就是慢。而基于tcp或者命名管道,又不跨平台。因此grpc很是适合某些特殊的场景中使用。尤为是他的消息交换是json,比wcf的xml轻量级不少。框架
二 配置说明 tcp
vs2017简单的安装几个nuget包:分布式
为项目添加proto文件,查看工程文件工具
<ItemGroup> <Protobuf Include="proto\order.proto" CompileOutputs="false" /> </ItemGroup>
CompileOutputs:这个配置属性意思就是不要编译进程序集google
<ItemGroup> <Protobuf Include="**/*.proto" OutputDir="%(RelativePath)" CompileOutputs="false" /> </ItemGroup>
OutputDir :这个属性意思就很明显了,输出目录
<ItemGroup> <Protobuf Include="**/*.proto" OutputDir="%(RelativePath)" CompileOutputs="false" GrpcServices="None" /> <Protobuf Update="**/hello/*.proto;**/bye/*.proto" GrpcServices="Both" /> </ItemGroup>
<Protobuf Update="**/hello/*.proto;**/bye/*.proto" GrpcServices="Both" /> 告诉插件只有这个节点配置的proto才进行更新,这是针对大一点的项目,不想让它生成整个项目的proto
GrpcServices是指生成客户端,仍是服务端,仍是两部分都生成。
<ItemGroup> <Protobuf Include="**/*.proto" OutputDir="%(RelativeDir)" CompileOutputs="false" GrpcServices="None" /> </ItemGroup>
GrpcServices="None" 只生成message不生成servicesspa
<ItemGroup> <Protobuf Include="../**/*.proto" ProtoRoot=".." OutputDir="%(RelativeDir)" CompileOutputs="false" /> </ItemGroup>