mirror of
https://codeberg.org/JasterV/grpc-slides.git
synced 2026-04-26 18:40:03 +00:00
Update slides
This commit is contained in:
parent
ff03569c2e
commit
09eef7420d
2 changed files with 95 additions and 26 deletions
|
|
@ -351,6 +351,19 @@ section.has-light-background h6 {
|
||||||
box-shadow: 0 0 20px rgba(0, 0, 0, 0.55);
|
box-shadow: 0 0 20px rgba(0, 0, 0, 0.55);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*********************************************
|
||||||
|
* LAYOUT
|
||||||
|
*********************************************/
|
||||||
|
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.column {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************************
|
/*********************************************
|
||||||
* NAVIGATION CONTROLS
|
* NAVIGATION CONTROLS
|
||||||
*********************************************/
|
*********************************************/
|
||||||
|
|
|
||||||
|
|
@ -396,13 +396,11 @@ note:
|
||||||
- **Health check** of services
|
- **Health check** of services
|
||||||
- **Interceptors**
|
- **Interceptors**
|
||||||
- **Reflection**
|
- **Reflection**
|
||||||
- **Code generation** from proto definitions
|
- **Stub generation** from protos
|
||||||
- RPC cancellation via **timeouts**
|
- RPC cancellation via **timeouts**
|
||||||
- Bidirectional **streaming**
|
|
||||||
- **Load balancing**
|
|
||||||
- Request/Response **compression**
|
- Request/Response **compression**
|
||||||
- **TLS**
|
|
||||||
- Extensible via **Tower** services
|
- Extensible via **Tower** services
|
||||||
|
- ...
|
||||||
|
|
||||||
note:
|
note:
|
||||||
|
|
||||||
|
|
@ -445,7 +443,79 @@ tonic_build::configure()
|
||||||
|
|
||||||
note:
|
note:
|
||||||
|
|
||||||
First we need to talk about how do we generate code from our protobuf definitions.
|
- prost_build generates types from the message definitions
|
||||||
|
- tonic_build generates the Client & Server stubs
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Generated types
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="column">
|
||||||
|
|
||||||
|
```rust
|
||||||
|
// Generated Request
|
||||||
|
pub struct DeclineRenewalRequest {
|
||||||
|
pub policy_id: String,
|
||||||
|
pub requested_at: Option<Timestamp>,
|
||||||
|
pub description: Option<String>,
|
||||||
|
pub reason: Option<Reason>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Reason {
|
||||||
|
Customer(i32),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generated Response
|
||||||
|
pub struct DeclineRenewalResponse {
|
||||||
|
pub policy_id: String,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
|
||||||
|
```rust
|
||||||
|
#[repr(i32)]
|
||||||
|
pub enum CustomerDeclineRenewalReason {
|
||||||
|
Unspecified = 0,
|
||||||
|
CompetitorOffer = 1,
|
||||||
|
VehicleSold = 2,
|
||||||
|
VehicleNotPurchased = 3,
|
||||||
|
VehicleDeregistration = 4,
|
||||||
|
NoInsuranceWanted = 5,
|
||||||
|
DoesNotKnow = 6,
|
||||||
|
WantsGreenCard = 7,
|
||||||
|
IncorrectEffectiveDate = 8,
|
||||||
|
IncorrectPersonalData = 9,
|
||||||
|
IncorrectDataOther = 10,
|
||||||
|
PaymentMethodOrDate = 11,
|
||||||
|
DeceasedPolicyHolder = 12,
|
||||||
|
CoverageChange = 13,
|
||||||
|
DissatisfactionService = 14,
|
||||||
|
UnderwritingRules = 15,
|
||||||
|
MovingToAnotherCountry = 16,
|
||||||
|
ProductService = 17,
|
||||||
|
PolicyHolderChange = 18,
|
||||||
|
PriceIncrease = 19,
|
||||||
|
Other = 20,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</div></div>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Generated types
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub trait PolicyManagementService {
|
||||||
|
async fn decline_renewal(
|
||||||
|
&self,
|
||||||
|
request: Request<DeclineRenewalRequest>,
|
||||||
|
) -> Result<Response<DeclineRenewalResponse>, Status>
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
## Exposing the generated code as a library
|
## Exposing the generated code as a library
|
||||||
|
|
@ -479,7 +549,7 @@ pub mod policy_service {
|
||||||
|
|
||||||
note:
|
note:
|
||||||
|
|
||||||
We need to expose the generated code through our lib.rs
|
- We must expose the generated code through our lib.rs when building a library
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -489,24 +559,6 @@ We need to expose the generated code through our lib.rs
|
||||||
|
|
||||||
## Filling the gaps
|
## Filling the gaps
|
||||||
|
|
||||||
```rust
|
|
||||||
pub trait PolicyManagementService {
|
|
||||||
async fn decline_renewal(
|
|
||||||
&self,
|
|
||||||
request: Request<DeclineRenewalRequest>,
|
|
||||||
) -> Result<Response<DeclineRenewalResponse>, Status>
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
note:
|
|
||||||
|
|
||||||
We get a trait generated from the Protobuf Service definition
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Filling the gaps
|
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use es_policy_grpc::policy_service::v1::PolicyManagementService;
|
use es_policy_grpc::policy_service::v1::PolicyManagementService;
|
||||||
use es_policy_grpc::messages::decline_renewal::request::v1::DeclineRenewalyRequest;
|
use es_policy_grpc::messages::decline_renewal::request::v1::DeclineRenewalyRequest;
|
||||||
|
|
@ -1035,9 +1087,13 @@ service Health {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This definition is provided by the official gRPC docs, each language runtime might implement it or not.
|
|
||||||
|
|
||||||
[https://github.com/grpc/grpc/blob/master/doc/health-checking.md](https://github.com/grpc/grpc/blob/master/doc/health-checking.md)
|
[https://github.com/grpc/grpc/blob/master/doc/health-checking.md](https://github.com/grpc/grpc/blob/master/doc/health-checking.md)
|
||||||
|
|
||||||
|
note:
|
||||||
|
|
||||||
|
- Official service definition from the gRPC documentation
|
||||||
|
- Some languages might implement it and others might not
|
||||||
|
|
||||||
---
|
---
|
||||||
## Enabling the health service
|
## Enabling the health service
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue