当前位置:   article > 正文

gRPC-Java_java @grpcclient 为空

java @grpcclient 为空

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

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号