gRPC-Java

What is gRPC?

  • gRPC is a high-performance open-source feature-rich RPC framework

  • gRPC is originally developed by Google

  • Now it is a part of the Cloud Native Computing Foundation - CNCF

  • RPC stands for Remote Procedure Calls

What is Remote Procedure Calls?

  • it is a protocol that allows a program to

    • execute a procedure of another program located in other computer

    • without the deveoper explicity coding the details for the remote interaction

  • in the client code ,it looks like we’re just calling a function of the server code directly

How gRPC works?

  • Client has a fenerated stub that provides the same methods as the server

  • the stub calls gRPC framework under the hood to exchange information over netwoek

  • Client and server user stubs to interact with each other, so they only need to implement their core service logic

How stubs are generated?

  • API contracts description

    • The service and paload messages are defined using Protocol Buffer
  • Server and client stubs are generated by the

    • Protocol Buffer compiler

    • gRPC plugins of each language

Why gRPC uses Protocol Buffer?

  • Human-readable Interface Degintion Language(IDL)

  • Programming languages interoperable:

    • Code generators for many languages
  • Binary data representation

    • Smaller size

    • Faster to transport

    • More efficient to serialize / deserialize

  • Strongly typed contract

  • Conventions for API evolation

    • Backward & forward compatibility
  • Alternative options

    • Google faltbuffers

    • Microsoft bond

What languages are supported by gRPC?

  • 10 officially supported languages

    • pure implementation:Go,Java,NodeJs

    • Wrap C-gRPC core:C/C++,C#,Objective-C Python ,Ruby,Dart,PHP

  • Many other unofficial libraries: Swift,Rust ,TypeScript,Haskell,etc.

What makes gRPC efficient?

GRPC Uses HTTP/2 as its transfer protocol

  • Binary framing

    • More performant and robust

    • Lighter to transpot, safer to decode

    • Great combination with Protocol Buffer

  • Header compression using HPACK

    • Reduce overhead and improve performance
  • multiplexing

    • Send multiple requests and responses in parallel over a single TCP connection

    • reduce latency and improve network utilization

  • Server push

    • One client request ,multiple responses

    • Reduce round-trip latency

How HTTP/2 works under the hood

  • single TCP connection carries multiple bidirectional streams

  • Each stream has a unique ID and caries multiple bidirectional messages

  • Each message (request/response) is broken down into multiple binary frames

  • Frame is the smallest unit that carries different types of data: HEADERS, SETTINGS, PRIORITY,DATA,etc.

  • Frame from different streams are interleaved and then reassembled on the other side

Where gRPC is well suited to?

  • Microservice

    • Low latency and high throughput communication

    • Strong API contract

  • Polyglot environments

    • Code generation out of the box for many languages
  • Point-to-point realtime communication

    • Excellent support for bidirectional streaming
  • Network constrained environments

    • Lightweight message format

What will we do?

  • install Java Development Kit

  • install Intellij IDEA

  • Setup a new Gradle project

    • install pluhins for protobuf and gRPC

    • Config automatic code generation upon build

  • Use Protobuf options to customise generated hava codes

to be continued

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值