- What is gRPC?
- RPC Framework
- vs. REST
- Binary vs. human-readable serialization
- No HTTP verb nomenclature
- Shared contract
- Requires special tooling
- HTTP2
- multiplexing / streaming
- One connection, multiple bi-directional requests/responses
- Companies that use it:
- Uber, Netflix, Spotify, DropBox
- Cross-platform
- Supported languages: Documentation | gRPC
-
Open sln
-
Add to appsettings.json (this adds verbosity to logging, making it more clear when GRPC service is invoked):
"Microsoft.AspNetCore.Hosting": "Information", "Microsoft.AspNetCore.Routing.EndpointMiddleware": "Information"
-
Show
greet.proto
- Explain.
- Show Properties.
-
Show
GreeterService.cs
- Show Generated class
- Demonstrate updating
-
Run
- Demonstrate trying to access in browser
-
Open sln
-
Copy Protos folder from Server
-
Open Greet.proto, change namespace
-
Add to .csproj (need to unload and reload)
<ItemGroup> <Protobuf Include="Protos\greet.proto" GrpcServices="Client" /> </ItemGroup>
-
Run, demonstrating communication with server.
- Create order.proto
- Talk about datetime. Include this link:
- Create a C# OrderService
- Try to inherit from OrderProtoService.
- It doesn't work, why not?
- Need to change compile options.
- Add to
Program.cs
- Copy
order.proto
from server to client. - Add to .csproj
- Add order-client-program-v1.cs
- Demonstrate
- Add delay to order provider to simulate server latency.
- Demonstrate how latency creates inefficicies with unary calls.
- Update order.proto with order-v2.proto, which adds a streaming method.
- Update order service with OrderService-v2.cs.
- Update client with order-client-program-v2.cs.
- Re-run server and client.
- Demonstrate how streaming method is more performant.
-
Update client with order-client-program-v3
-
Explain DNS service discovery
- Can use DNS service (SRV) records.
-
Start multiple instances of server, demonstrating load balancing / failover:
dotnet run --no-build --urls="http://localhost:5126/" --project "S:\Projects\Grpc.Demo\Server\Grpc.Demo.Server\Grpc.Demo.Server.csproj" dotnet run --no-build --urls="http://localhost:5127/" --project "S:\Projects\Grpc.Demo\Server\Grpc.Demo.Server\Grpc.Demo.Server.csproj" dotnet run --no-build --urls="http://localhost:5128/" --project "S:\Projects\Grpc.Demo\Server\Grpc.Demo.Server\Grpc.Demo.Server.csproj"
-
Switch round robin config to
PickFirstConfig
.
- Requiress 4.6.1 or later
- Requires Grpc.Core, a maintenance mode project
- Doesn't support outbound streams
Authentication and authorization in gRPC for ASP.NET Core | Microsoft Docs
- Supported:
- Simplest -- bearer token
- Certificate
- JWT Tokens
- OAuth
- OpenId Connect
- Similar to securing a Web API app (authorization attributes, etc.)
- GRPC Server (final version created in this demo)
- GRPC Client (final version created in this demo)
- GRPC Legacy (.NET Framework) Client