Book Image

Microservices Communication in .NET Using gRPC

By : Fiodar Sazanavets
Book Image

Microservices Communication in .NET Using gRPC

By: Fiodar Sazanavets

Overview of this book

Explore gRPC's capabilities for faster communication between your microservices using the HTTP/2 protocol in this practical guide that shows you how to implement gRPC on the .NET platform. gRPC is one of the most efficient protocols for communication between microservices that is also relatively easy to implement. However, its official documentation is often fragmented and.NET developers might find it difficult to recognize the best way to map between C# data types and fields in gRPC messages. This book will address these concerns and much more. Starting with the fundamentals of gRPC, you'll discover how to use it inside .NET apps. You’ll explore best practices for performance and focus on scaling a gRPC app. Once you're familiar with the inner workings of the different call types that gRPC supports, you'll advance to learning how to secure your gRPC endpoints by applying authentication and authorization. With detailed explanations, this gRPC .NET book will show you how the Protobuf protocol allows you to send messages efficiently by including only the necessary data. You'll never get confused again while translating between C# data types and the ones available in Protobuf. By the end of the book, you’ll have gained practical gRPC knowledge and be able to use it in .NET apps to enable direct communication between microservices.
Table of Contents (17 chapters)
1
Section 1: Basics of gRPC on .NET
5
Section 2: Best Practices of Using gRPC
9
Section 3: In-Depth Look at gRPC on .NET

Questions

Answer the following questions to test your knowledge of this chapter:

  1. Please select the false statement:

    A. In Protobuf, a service is defined by the service keyword, while its methods are defined by the rpc keyword.

    B. You cannot have a Protobuf message definition without any fields.

    C. A Protobuf message can have collections of objects and can use other message definitions as field types.

    D. You have to specify a request object in a response object inside a gRPC method definition and you can only use a single object type in each of those.

  2. Which platforms can you run a .NET implementation of gRPC on?

    A. Windows, Linux, and macOS

    B. Windows and macOS only

    C. Unix-based (macOS and Linux) only

    D. Windows only

  3. How do you enable server-side gRPC components in .NET applications?

    A. So long as you reference the Grpc.AspNetCore NuGet package, it will be automatically enabled for you.

    B. You just need to add a proto file to your project; the compiler will do everything else for you.

    C. You need to define a proto element inside the project file. It can be blank or you can set its GrpcServices attribute to either Server or Both.

    D. You need to define a proto element inside the project file and you must set its GrpcServices attribute to Server.

  4. After adding the relevant proto files to your server-side application project, what modifications do you need to make to your code?

    A. You just need to override the methods from the auto-generated C# code files with your functionality.

    B. You need to modify the auto-generated C# classes and add your functionality to them.

    C. You need to create a new class that inherits from the auto-generated base class, add gRPC to your application services via the ConfigureServices method of the Startup class, and then register the newly created class as one of the endpoints in your middleware.

    D. The system will generate all the required code for you. You just need to fill the methods with your logic.

  5. Can the .NET implementation of the .NET client call RPCs both synchronously and asynchronously?

    A. It can only call methods synchronously.

    B. It can only call methods asynchronously.

    C. There is both a synchronous and asynchronous version of each method that's generated for the client to use.

    D. All auto-generated methods are asynchronous, but you can change the implementation to make them synchronous.