Home Page Icon
Home Page
Table of Contents for
Microservices Communication in .NET Using gRPC
Close
Microservices Communication in .NET Using gRPC
by Fiodar Sazanavets
Microservices Communication in .NET Using gRPC
Microservices Communication in .NET Using gRPC
Contributors
About the author
About the reviewer
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Code in Action
Download the color images
Conventions used
Get in touch
Share Your Thoughts
Section 1: Basics of gRPC on .NET
Chapter 1: Creating a Basic gRPC Application on ASP.NET Core
Technical requirements
Introduction to gRPC
gRPC on ASP.NET Core
Using gRPC in your own distributed ASP.NET Core application
Preparing your system
Setting up your environment on Windows
Setting up your environment on Mac
Setting up your environment on Linux
Downloading the .NET SDK (all operating systems)
Setting up a gRPC server
Initializing an ASP.NET Core project via an IDE
Adding gRPC server components to an ASP.NET Core project
Adding some code to use gRPC components
Setting up a gRPC client
Initializing the project for the client application
Adding gRPC client components to the application
Applying gRPC client components to the code
Understanding how proto files generate C# code
Where is auto-generated code stored?
Modifying Protobuf namespaces
Sharing a proto file between the client and the server
Creating a shared class library
Adding shared gRPC components to the class library
Sharing gRPC dependencies between different projects
Running a gRPC service on Mac
Configuring server-side components
Modifying the client-side configuration
Summary
Questions
Further reading
Chapter 2: When gRPC Is the Best Tool and When It Isn't
Technical requirements
Why gRPC is a great tool for microservices
Setting up a solution and shared dependencies
Setting up the status manager microservice
Setting up a REST API gateway service
Launching the distributed application
How gRPC can be a good tool for asynchronous communication
Adding client-streaming and server-streaming gRPC endpoints
Configuring the gRPC client for asynchronous communication
Testing asynchronous gRPC endpoints
Why gRPC is not the best tool for browsers
Setting up a Blazor WebAssembly gRPC client
Modifying the gRPC server to enable gRPC-Web
Launching the gRPC-Web application
Where SignalR would beat gRPC
Setting up a SignalR application
Adding a SignalR client and launching the application
Summary
Questions
Further reading
Chapter 3: Protobuf – the Communication Protocol of gRPC
Technical requirements
The RPC types supported by gRPC
The RPC types that Protobuf supports
Making comments in Protobuf
Reviewing the native Protobuf data types
Integer data types
Non-integer numeric types
Non-numeric data types
Enums
Nested messages
Using collections in Protobuf
Repeated fields
Map fields
Using special keywords in Protobuf
How the oneof keyword can make communication more efficient
Customizing the behavior with the option keyword
Referencing other proto files
Importing external proto packages
Referencing internal proto files
Using proto files as relays
Summary
Questions
Further reading
Section 2: Best Practices of Using gRPC
Chapter 4: Performance Best Practices for Using gRPC on .NET
Technical requirements
Why you need to reuse a gRPC channel
Setting up the server application
Setting up the client application
Comparing the performance of different client types
How to not get held up by a concurrent stream limit
Configuring connection concurrency on the gRPC client
Comparing the performance between a single connection and multiple connections
Ensuring that your connection remains alive
Setting up keep-alive pings on the gRPC client
When streaming is better than individual calls
Setting up a bi-directional streaming RPC
Monitoring the performance of the bi-directional streaming call
Using binary payloads to decrease the data's size
Adding binary fields to Protobuf
Summary
Questions
Further reading
Chapter 5: Applying Versioning to the gRPC API
Technical requirements
Why an API versioning strategy is important
Creating a server application
Implementing the server-side gRPC components
Creating the gRPC client application
Implementing the gRPC client logic
Verifying that the client can talk to the server
What the sequence numbers in the proto file represent
Modifying the Protobuf definition in the server application
Modifying the Protobuf definition in the client application
Launching modified applications
Why you must not modify existing fields in future Protobuf versions
Modifying Protobuf definitions on the client side
Launching the applications
Making further changes to the client application
Re-launching the applications
How to deprecate old, unused fields in gRPC
Applying the reserved keyword to the server-side Protobuf interface
Testing the application
How to factor in API versioning at the design stage
Adding multiple Protobuf versions to the server application
Allowing the server application to use multiple Protobuf versions
Making the gRPC client implementation version-specific
Making a gRPC call to a versioned endpoint
Summary
Questions
Further reading
Chapter 6: Scaling a gRPC Application
Technical requirements
Introduction to load balancing
Adding shared gRPC dependencies
Creating a shared library for server-side application instances
Creating multiple instances of the server-side application
Creating a client application
Running a load-balanced application
Client-side load balancing with gRPC
Updating the NuGet package
Enabling client-side load balancing components
Enabling a DNS resolver for the load balancer
Using a static resolver for the load balancer
Creating custom load balancers and resolvers
Proxy load balancing with gRPC
Building a web application to act as a proxy
Launching the HTTP/2 proxy
Summary
Questions
Further reading
Section 3: In-Depth Look at gRPC on .NET
Chapter 7: Using Different Call Types Supported by gRPC
Technical requirements
Making unary calls on gRPC
Setting up shared gRPC dependencies
Creating server-side implementations of the Protobuf definitions
Building the gRPC client
Applying different types of client-side call implementations
Using gRPC dependencies in the client application
Testing different types of unary call endpoints
Streaming data from the client
Adding a client-streaming call to the server application
Adding client logic for a client-streaming gRPC call
Reading streams from the server
Adding a server-streaming RPC to Protobuf
Setting up a server-streaming call on the server side
Making a server-streaming call from a gRPC client
Enabling bi-directional streaming
Enabling server-side components for bi-directional streaming
Adding a client-side implementation of a bi-directional streaming call
Testing how to stream gRPC calls
Summary
Questions
Further reading
Chapter 8: Using Well-Known Types to Make Protobuf More Handy
Technical requirements
Using nullable types in Protobuf
Setting up a gRPC server application
Examining auto-generated code for wrapper fields
Adding logic to gRPC server application
Setting up shared dependencies
Setting up the gRPC client
Running the application
Using dates and times in Protobuf
Adding timestamp and duration to the server
Applying changes to the gRPC client and launching the app
Exchanging empty messages
Adding the Empty data type to the server-side application
Applying an Empty object on the client
Using loosely typed fields in a Protobuf message
Adding Any and Value data types to the gRPC server
Populating the Any and Value fields from the gRPC client
Summary
Questions
Further reading
Chapter 9: Securing gRPC Endpoints in Your ASP.NET Core Application with SSL/TLS
Technical requirements
Configuring the gRPC client and server for unencrypted communication
The role of TLS certificates
Setting up a gRPC service application
Removing TLS on both HTTP/1.1 and HTTP/2
Exposing Protobuf definitions to clients
Building the client for gRPC communication
Adding the remaining client logic
Creating and trusting a self-signed certificate
The basics of a TLS certificate
Trusting a default development certificate
Creating a self-signed certificate on Windows using PowerShell
Creating a self-signed certificate on Unix using OpenSSL
Applying a certificate on ASP.NET Core
Testing custom certificates and HTTPS redirection
Applying certificate authentication on the gRPC client and server
Configuring the gRPC server for certificate authentication
Enabling certificate authentication on the gRPC client
Testing certificate authentication
Summary
Questions
Further reading
Chapter 10: Applying Authentication and Authorization to gRPC Endpoints
Technical requirements
Setting up the authentication backend
OpenID Connect and OAuth flow
Configuring IdentityServer4
Adding SSO users, roles, and clients
Forcing login redirect on a web application
Restricting gRPC endpoints to authenticated users
Setting up shared gRPC dependencies
Setting up the gRPC server
Enabling gRPC client functionality
Restricting endpoints to authorized users only
Configuring SSO provider to insert role claim into the JWT
Applying different authorization rules to different gRPC endpoints
Applying gRPC client changes
Summary
Questions
Further reading
Chapter 11: Using Logging, Metrics, and Debugging in gRPC on .NET
Technical requirements
Debugging gRPC client components inside a .NET application
Setting up shared gRPC dependencies
Adding a gRPC service application and getting it to display detailed errors
Adding a gRPC client with additional debugging capabilities
Viewing gRPC error information on the client
Debugging gRPC server components inside a .NET application
Viewing the debug output on the gRPC server console
Applying logs to gRPC
Configuring a logger on the gRPC client
Applying a logger on the gRPC server
Testing our log output
Applying metrics to gRPC
Configuring metrics on the gRPC server
Enabling metric collection on the gRPC client
Viewing gRPC metrics
Summary
Questions
Further reading
Assessments
Chapter 1, Creating a Basic gRPC Application on ASP.NET Core
Chapter 2, When gRPC Is the Best Tool and When It Isn't
Chapter 3, Protobuf – the Communication Protocol of gRPC
Chapter 4, Performance Best Practices for Using gRPC on .NET
Chapter 5, Applying Versioning to the gRPC API
Chapter 6, Scaling a gRPC Application
Chapter 7, Using Different Call Types Supported by gRPC
Chapter 8, Using Well-Known Types to Make Protobuf More Handy
Chapter 9, Securing gRPC Endpoints in Your ASP.NET Core Application with SSL/TLS
Chapter 10, Applying Authentication and Authorization to gRPC Endpoints
Chapter 11, Using Logging, Metrics, and Debugging in gRPC on .NET
Why subscribe?
Other Books You May Enjoy
Packt is searching for authors like you
Share Your Thoughts
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
Microservices Communication in .NET Using gRPC
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset