From 0eba94d0a9f6d48a7a73264a4eabc19903b30e66 Mon Sep 17 00:00:00 2001 From: JasterV <49537445+JasterV@users.noreply.github.com> Date: Sun, 15 Jun 2025 17:21:37 +0200 Subject: [PATCH] Update presentation --- docs/learning_grpc.md | 101 ++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 58 deletions(-) diff --git a/docs/learning_grpc.md b/docs/learning_grpc.md index 2b0f978..9a69cd9 100644 --- a/docs/learning_grpc.md +++ b/docs/learning_grpc.md @@ -56,7 +56,7 @@ They auto-generated the client and server stubs: --- ### Interface Definition Language -```protobuf +```thrift struct Phone { 1: i32 id, 2: string number, @@ -68,6 +68,10 @@ service PhoneService { } ``` +
+Codegen tools will generate gRPC stubs from IDL code +
+An example of Thrift, an IDL used in Facebook's RPC framework
@@ -167,13 +171,13 @@ Can be useful for: Authentication & tracing --- ### And many more features -- **Flow control** for streaming -- RPC automatic & manual **cancellations** -- **Reflection** (Service discoverability & ease debugging) -- **Load balancing** (Client requests can be load balanced between multiple servers) -- Call **retries** - **Health checking** (Service-specific health checking) - **Interceptors** (Middleware for RPCs) +- **Reflection** (Service discoverability & ease debugging) +- RPC automatic & manual **cancellations** +- Call **retries** +- **Flow control** for streaming +- **Load balancing** (Client requests can be load balanced between multiple servers) note: @@ -214,6 +218,28 @@ Here we will focus on the IDL and the tooling, we won't focus on the serializati ### Protobufs as an Interface Definition Language --- +### Defining messages + +```protobuf +// amend_termination/request/v1/request.proto +syntax = "proto3"; + +package amend_termination.request.v1; + +message AmendTerminationRequest { + string policy_id = 1; + google.protobuf.Timestamp requested_at = 2; + google.protobuf.Timestamp interruption_at = 3; + optional string description = 4; + oneof reason { + CustomerTerminateReason customer = 5; + PrimaTerminateReason prima = 6; + } +} +``` + +--- + ### Defining a service ```protobuf @@ -226,33 +252,23 @@ import "amend_termination/request/v1/request.proto"; import "amend_termination/response/v1/response.proto"; service PolicyManagementService { - rpc AmendTermination(amend_termination.request.v1.AmendTerminationRequest) returns (amend_termination.response.v1.AmendTerminationResponse); + rpc AmendTermination(AmendTerminationRequest) returns (AmendTerminationResponse); } ``` --- -### Defining messages -```protobuf -// amend_termination/request/v1/request.proto -syntax = "proto3"; +### Remarkable features of Protocol buffers -package amend_termination.request.v1; +- **Strongly typed** data +- **Language** and **platform neutral** +- **Compact binary format** +- Support for **RPC service definition** +- **Backward and Forward compatibility** -import "terminate_policy/request/v1/request.proto"; -import "google/protobuf/timestamp.proto"; +note: -message AmendTerminationRequest { - string policy_id = 1; - google.protobuf.Timestamp requested_at = 2; - google.protobuf.Timestamp interruption_at = 3; - optional string description = 4; - oneof reason { - terminate_policy.request.v1.CustomerTerminateReason customer = 5; - terminate_policy.request.v1.PrimaTerminateReason prima = 6; - } -} -``` +Give a short example of why it is backward and forward compatible. Mention tags. --- ### The protoc compiler @@ -289,35 +305,6 @@ Explain that it builds on top of protoc. Be very short here, just mention the to --- -### Buf CLI - -```bash -buf format -``` - -```bash -buf lint -``` - -```bash -buf breaking --against ".git#branch=master" -``` - - ---- -### Remarkable features of Protocol buffers - -- **Strongly typed** data -- **Language** and **platform neutral** -- **Compact binary format** -- **Backward and Forward compatibility** -- Support for **RPC service definition** - -note: - -Give a short example of why it is backward and forward compatible. Mention tags. - ---- ## gRPC in the Rust ecosystem @@ -331,9 +318,9 @@ Give a short example of why it is backward and forward compatible. Mention tags. --- # Tonic -