This project demonstrates the usage of gRPC, a high-performance, open-source framework for remote procedure calls (RPC) developed by Google. gRPC allows communication between different systems and programming languages using a simplified interface definition.
gRPC provides four main communication patterns:
-
Unary RPC This is the traditional request-response method where the client sends a single request to the server and waits for a response.
-
Server-side Streaming RPC: In this pattern, the client sends a request to the server, and the server responds with a stream of messages. The client can read these messages from the stream until the server is done.
-
Client-side Streaming RPC: Here, the client sends a stream of messages to the server. The server processes these messages and eventually sends a single response back to the client.
-
Bidirectional Streaming RPC: This method allows both the client and the server to send and receive streams of messages. The client and server can independently read and write messages on the same connection.
- Create a new directory for your project and navigate into it:
mkdir go-grpc cd go-grpc mkdir client server proto
- Install the gRPC Go plugin:
go install google.golang.org/protobuf/cmd/[email protected] go install google.golang.org/grpc/cmd/[email protected] export PATH="$PATH:$(go env GOPATH)/bin"
- Initialize a Go module:
go mod init github.com/your_username/basic-go-grpc go mod tidy
- Create the proto file with the required services and messages in the proto directory.
- Generate the .pb.go files from the proto file:
If the greet.proto file is in the proto directory, run:
```shell
protoc --go_out=. --go-grpc_out=. proto/greet.proto
If the greet.proto file contains a different path, adjust the command accordingly.
- Create the server and client directories and create the main.go files with the necessary controllers and services.
-
Install the dependencies:
go mod tidy
-
Run the server:
go run server/main.go
-
Run the client:
go run client/main.go
Note: When you want to Run a Particular Communication Method of RPC, Just Simply Uncomment one of the line in Client/main.go