liveBook · Manning

Service method

As explained in gRPC Microservices in Go

A service method is a remotely callable operation declared by a service interface with specified input and output message types.

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

How gRPC Microservices in Go covers it

How deep it goes
Defines message types, generates client and server stubs, and connects calls to endpoints, while deferring advanced exception handling.
Examples
Uses Payment.Create, Order.Create, CreatePaymentRequest, CreatePaymentResponse, and grpcurl invocation.
What it assumes
Assumes awareness of service boundaries, while teaching message definitions, IDL-based contracts, and generated language-specific clients.
What you can do after
Build it from scratch by defining a proto contract, generating stubs, implementing server logic, and invoking the method from a client.
How it connects
Connects protocol buffers, gRPC, request and response messages, client stubs, server stubs, and service endpoints.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of gRPC Microservices in Go. The section links point to the parts of the book it draws on.