总结
增加、修改一个grpc接口步骤:
1.修改proto文件,新增修改一个service,相应的请求和回复的message
2.使用protoc生成go代码
3.server和cilent分别调用生成的go包里的方法
这个也就是平台中立的体现,没有完全的平台中立,只是从新设计。
thrift和 grpc的优劣:
1.依据网络进行合理选择
2.thrift是Facebook的开源rpc框架,thrift的rpc,一次调用在收到回复之前,占用一个TCP连接的,当并发量很高,而一次调用耗时又很长的时候,thrift会出现连接被占满的情况,导致调用堆积,延时增大.
3.grpc是基于http-2设计的,http-2的一个重要特点是在单个TCP连接上可以复用多个请求.而grpc,多个调用可以复用一个连接,这样显然就比thrift支持的并发调用数量更高。
具体实现(照猫画虎)
- 使用protoc生成 proto文件,类如grpc 提供的example中的helloworld
执行protoc.exe ,发现这个编译器插件支持的大概命令
以及版本,我的是libprotoc 3.6.1
$ protoc.exe
Usage: D:\GO\bin\protoc.exe [OPTION] PROTO_FILES
Parse PROTO_FILES and generate output based on the options given:
-IPATH, --proto_path=PATH Specify the directory in which to search for
imports. May be specified multiple times;
directories will be searched in order. If not
given, the current working directory is used.
--version Show version info and exit.
-h, --help Show this text and exit.
--encode=MESSAGE_TYPE Read a text-format message of the given type
from standard input and write it in binary
to standard output. The message type must
be defined in PROTO_FILES or their imports.
--decode=MESSAGE_TYPE Read a binary message of the given type from
standard input and write it in text format
to standard output. The message type must
be defined in PROTO_FILES or their imports.
--decode_raw Read an arbitrary protocol message from
standard input and write the raw tag/value
pairs in text format to standard output. No
PROTO_FILES should be given when using this
flag.
--descriptor_set_in=FILES Specifies a delimited list of FILES
each containing a FileDescriptorSet (a
protocol buffer defined in descriptor.proto).
The FileDescriptor for each of the PROTO_FILES
provided will be loaded from these
FileDescriptorSets. If a FileDescriptor
appears multiple times, the first occurrence
will be used.
-oFILE, Writes a FileDescriptorSet (a protocol buffer,
--descriptor_set_out=FILE defined in descriptor.proto) containing all of
the input files to FILE.
--include_imports When using --descriptor_set_out, also include
all dependencies of the input files in the
set, so that the set is self-contained.
--include_source_info When using --descriptor_set_out, do not strip
SourceCodeInfo from the FileDescriptorProto.
This results in vastly larger descriptors that
include information about the original
location of each decl in the source file as
well as surrounding comments.
--dependency_out=FILE Write a dependency output file in the format
expected by make. This writes the transitive