Write your .proto file
.proto is a file which contains all definition of the gRPC service and the method request and response types using the format of protocol buffers.
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
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;
}
Last updated
Was this helpful?