0
0
Microservicessystem_design~10 mins

gRPC for internal communication in Microservices - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a gRPC service method.

Microservices
service UserService {
  rpc GetUser([1]) returns (UserResponse);
}
Drag options to blanks, or click blank then click option'
AUserRequest
BUserId
CUserResponse
DUserData
Attempts:
3 left
💡 Hint
Common Mistakes
Using the response message type as input.
Using a field name instead of a message type.
2fill in blank
medium

Complete the code to create a gRPC client stub in Go.

Microservices
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
  log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
client := [1](conn)
Drag options to blanks, or click blank then click option'
ANewUserServiceClient
BNewGrpcClient
CNewClientStub
DNewServiceClient
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic or incorrect constructor function.
Forgetting to pass the connection object.
3fill in blank
hard

Fix the error in the server implementation to register the gRPC service.

Microservices
grpcServer := grpc.NewServer()
[1](grpcServer, &server{})
Drag options to blanks, or click blank then click option'
ARegisterUserServer
BRegisterGrpcServer
CRegisterService
DRegisterUserServiceServer
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic or incorrect registration function name.
Omitting the service implementation pointer.
4fill in blank
hard

Fill both blanks to define a unary gRPC method handler signature in Go.

Microservices
func (s *server) GetUser(ctx context.Context, [1] *UserRequest) (*UserResponse, [2]) {
  // implementation
}
Drag options to blanks, or click blank then click option'
Areq
Berr
Crequest
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names.
Returning a non-error type as the second return value.
5fill in blank
hard

Fill all three blanks to create a gRPC client call and handle the response in Go.

Microservices
resp, [1] := client.GetUser(context.Background(), &[2]{})
if [3] != nil {
  log.Fatalf("could not get user: %v", err)
}
// use resp
Drag options to blanks, or click blank then click option'
Aerr
BUserRequest
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names for error.
Passing incorrect request message types.