GRPC
Introduction
gRPC is a high-performance, open-source RPC framework that uses Protocol Buffers for serialization and HTTP/2 for transport. It enables efficient communication between services across different languages and platforms.
Define Your Service, Messages
syntax = "proto3";
package dvdrental.v1;
import "google/protobuf/empty.proto";
option go_package = "git.bibble.co.nz/bibble235/grpc_server_go/pb;pb";
// Film represents a movie in the DVD rental system
message Film {
// Unique identifier for the film
string id = 1;
// Title of the film
string title = 2;
// Description or synopsis of the film
string description = 3;
// Year the film was released
string release_year = 4;
}
// Actor represents a person who acts in films
message Actor {
// Unique identifier for the actor
string id = 1;
// First name of the actor
string first_name = 2;
// Last name of the actor
string last_name = 3;
}
// ActorList contains multiple Actor records
message ActorList {
// List of actors
repeated Actor actor = 1;
}
// FilmList contains multiple Film records
message FilmList {
// List of films
repeated Film film = 1;
}
// FilmIdRequest is used to request a specific film by ID
message FilmIdRequest {
// ID of the film to retrieve
string id = 1;
}
// ActorIdRequest is used to request a specific actor by ID
message ActorIdRequest {
// ID of the actor to retrieve
string id = 1;
}
// DVDRentalService provides operations to interact with the DVD rental system
service DVDRentalService {
// GetActor retrieves an actor by their ID
rpc GetActor(ActorIdRequest) returns (Actor);
// GetActorListWithStream streams all actors one by one
rpc GetActorListWithStream(google.protobuf.Empty) returns (stream Actor);
// GetActorListWithRepeated retrieves all actors in a single response
rpc GetActorListWithRepeated(google.protobuf.Empty) returns (ActorList);
// GetFilm retrieves a film by its ID
rpc GetFilm(FilmIdRequest) returns (Film);
// GetFilmListWithStream streams all films one by one
rpc GetFilmListWithStream(google.protobuf.Empty) returns (stream Film);
// GetFilmListWithRepeated retrieves all films in a single response
rpc GetFilmListWithRepeated(google.protobuf.Empty) returns (FilmList);
}
dotnet add package Grpc.Net.Client dotnet add package Google.Protobuf dotnet add package Grpc.Tools