- Unary RPC calls are the basic request/response model
- Client will send one message to the Server and will receive one response from Server
- Unary RPC are very well suited when:
- Data is small
- Start with Unary API and use Streaming API if performance is an issue
- For each RPC call the protocol buffer file will contain:
- Request message
- Response message
- Service definition
- Generate
welcome.pb.go
using below commandprotoc welcomepb/welcome.proto --go_out=plugins=grpc:.
- Open generated
welcome.pb.go
insidewelcomepb
package- Server specific code:
WelcomeServiceServer
WelcomeServiceServer
-Welcome(context.Context, *WelcomeRequest) (*WelcomeResponse, error)
RegisterWelcomeServiceServer(s *grpc.Server, srv WelcomeServiceServer)
- Client specific code:
WelcomeServiceClient
WelcomeServiceClient
-Welcome(ctx context.Context, in *WelcomeRequest, opts ...grpc.CallOption) (*WelcomeResponse, error)
NewWelcomeServiceClient(cc *grpc.ClientConn) WelcomeServiceClient
- Server specific code:
- Open
server/server.go
- Do steps mentioned in
01-code-generation
- Implement method
Welcome(ctx context.Context, request *welcomepb.WelcomeRequest) (*welcomepb.WelcomeResponse, error)
- Do steps mentioned in
- Open
client/client.go
- Do steps mentioned in
01-code-generation
- Create request object of
welcomepb.WelcomeRequest
- Request welcome service using
client.Welcome
- Do steps mentioned in