✒️
[Lab] gRPC
  • Introduction
  • Environment setup and prerequisite
  • Write your .proto file
  • Generate server and client code in Java
  • Implement the server code in Java
  • Implement the client in Java
  • Implement the client in GO
Powered by GitBook
On this page

Was this helpful?

Write your .proto file

PreviousEnvironment setup and prerequisiteNextGenerate server and client code in Java

Last updated 6 months ago

Was this helpful?

.proto is a file which contains all definition of the gRPC service and the method request and response types using the format of .

Under the workspace, we create folders src/main/proto and create our .proto file, calculator.proto.

cd ~/grpclab
mkdir -p src/main/proto
nano src/main/proto/calculator.proto
calculator.proto
syntax = "proto3";

package calculator;
option java_package = "cslab.grpclab";

// define 2 rpcs for Calculator service
service Calculator {
    rpc Sum(CalculationRequest) returns(CalculationRespond) {};
    rpc Product(CalculationRequest) returns(CalculationRespond) {};
}

//Define the structure of `CalculationRequest` which is the input of the rpcs
message CalculationRequest {
    float a = 1;
    float b = 2;
}

//Define the structure of `CalculationRequest` which is the output of the rpcs
message CalculationRespond {
    float result = 1;
}

protocol buffers