GRPC

作者: 一只重拾梦想的小水 | 来源:发表于2019-08-23 15:56 被阅读0次

message HelloRequest {
string greeting = 1;
}

message HelloResponse {
string reply = 1;
}

  • 原理:
    netty:异步/事件驱动的 网络应用程序服务器框架(高性能)
    Http2:流式、双向
    protobuf:序列化(节省网络带宽)

  • 使用:
    Starting from a service definition in a .proto file, gRPC provides protocol buffer compiler plugins that generate client- and server-side code.

使用:http://doc.oschina.net/grpc?t=60135
1、编写 .proto
2、protoc 编译 https://medium.com/@erika_dike/installing-the-protobuf-compiler-on-a-mac-a0d397af46b8

3、server: build\ 注册\ new\ bind(ip+port)\ listen(启动)
4、client: new实例化((ip+port, stub)\ service.method

  • 与http对比:
    http没文档就不知道细节,开发先服务端后客户端

grpc的idl就相当于文档,可以同时

  • 与thrift对比:
    都支持多语言
    性能 远差于thrift,因为用了http2,各大server支持不完善,不能负载均衡 ???
    GRPC尚未完全提供连接池、服务自动发现、进程内负载均衡等高级特性,需要开发人员额外的封装;

  • 优点:
    多语言
    stream

  • 缺点:
    GRPC尚未完全提供连接池、服务自动发现、进程内负载均衡等高级特性,需要开发人员额外的封装
    node调用不方便 ???

相关文章

网友评论

      本文标题:GRPC

      本文链接:https://www.haomeiwen.com/subject/ssjtectx.html