栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

gRPC-Java

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1005885.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号