A service method is a remotely callable operation declared in a gRPC service definition. It accepts a specified request message and returns a specified response message, giving clients a typed contract for interservice communication. section 2.5.1 section 1.1.2
Implement a service method across a service boundary by following this sequence:
- Define request and response messages and the service method in a .proto file. section 2.5.1
- Generate client and server stubs with protoc or another supported gRPC toolchain. section 2.5.1 section 1.1.2
- Implement server-side business logic and invoke the generated client stub from the consuming service. section 2.5.1
- Run the services and exercise the endpoint with a gRPC client. section 2.5.1 section 4.2.8
Calling an order method
An Order service can expose a Create method that accepts CreateOrderRequest and returns an order identifier. A grpcurl request sends JSON to Order/Create and receives a response such as {"orderId":"1"}. section 4.2.8
message CreatePaymentRequest {
int user_id = 1;
float64 price = 2;
}
message CreatePaymentResponse {
int bill_id = 1;
}
service Payment {
RPC Create(CreatePaymentRequest)
returns (CreatePaymentResponse) {}
}
A compact Payment definition shows how a service method connects a request message, a response message, and an RPC operation. section 2.5.1
