teach your micro services speak protocol buffers with grpc
play

Teach your (micro)services speak Protocol Buffers with gRPC. Mihai - PowerPoint PPT Presentation

Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com Whats inside? Whats inside? Message serialization and deserialization Whats inside? Message serialization


  1. Service code server = grpc.server( futures.ThreadPoolExecutor(max_workers=10)) route_planner_pb2_grpc.add_RoutePlannerServicer_to_server( Servicer(), server) server.add_insecure_port('[::]:12345') server.start()

  2. Service code server = grpc.server( futures.ThreadPoolExecutor(max_workers=10)) route_planner_pb2_grpc.add_RoutePlannerServicer_to_server( Servicer(), server) server.add_insecure_port('[::]:12345') server.start()

  3. Service code server = grpc.server( futures.ThreadPoolExecutor(max_workers=10)) route_planner_pb2_grpc.add_RoutePlannerServicer_to_server( Servicer(), server) server.add_insecure_port('[::]:12345') server.start()

  4. Implementing the client

  5. Implementing the client

  6. Client code channel = grpc.insecure_channel(‘localhost:12345') stub = route_planner_pb2_grpc.RoutePlannerStub(channel) request = route_planner_pb2.GetRoutesRequest( origin=CURRENT_LOCATION, destination=DESTINATION_COORDS) response = stub.GetRoutes(request)

  7. Client code channel = grpc.insecure_channel(‘localhost:12345') stub = route_planner_pb2_grpc.RoutePlannerStub(channel) request = route_planner_pb2.GetRoutesRequest( origin=CURRENT_LOCATION, destination=DESTINATION_COORDS) response = stub.GetRoutes(request)

  8. Client code channel = grpc.insecure_channel(‘localhost:12345') stub = route_planner_pb2_grpc.RoutePlannerStub(channel) request = route_planner_pb2.GetRoutesRequest( origin=CURRENT_LOCATION, destination=DESTINATION_COORDS) response = stub.GetRoutes(request)

  9. Client code channel = grpc.insecure_channel(‘localhost:12345') stub = route_planner_pb2_grpc.RoutePlannerStub(channel) request = route_planner_pb2.GetRoutesRequest( origin=CURRENT_LOCATION, destination=DESTINATION_COORDS) response = stub.GetRoutes(request)

  10. Client code channel = grpc.insecure_channel(‘localhost:12345') stub = route_planner_pb2_grpc.RoutePlannerStub(channel) request = route_planner_pb2.GetRoutesRequest( origin=CURRENT_LOCATION, destination=DESTINATION_COORDS) response = stub.GetRoutes(request)

  11. Client code channel = grpc.insecure_channel(‘localhost:12345') stub = route_planner_pb2_grpc.RoutePlannerStub(channel) request = route_planner_pb2.GetRoutesRequest( origin=CURRENT_LOCATION, destination=DESTINATION_COORDS) response = stub.GetRoutes(request)

  12. Client code (async) response_future = stub.GetRoutes.future(request) response_future.result()

  13. grpc_cli $ grpc_cli call localhost:12345 \ 
 RoutePlanner.GetRoutes \ 
 <<- PROTO 
 origin: <long: 0.0 lat: 0.0> 
 destination: <long: 1.1 lat: 1.1> 
 PROTO

  14. grpc_cli $ grpc_cli call localhost:12345 \ 
 RoutePlanner.GetRoutes \ 
 <<- PROTO 
 origin: <long: 0.0 lat: 0.0> 
 destination: <long: 1.1 lat: 1.1> 
 PROTO

  15. grpc_cli $ grpc_cli call localhost:12345 \ 
 RoutePlanner.GetRoutes \ 
 <<- PROTO 
 origin: <long: 0.0 lat: 0.0> 
 destination: <long: 1.1 lat: 1.1> 
 PROTO

  16. grpc_cli $ grpc_cli call localhost:12345 \ 
 RoutePlanner.GetRoutes \ 
 <<- PROTO 
 origin: <long: 0.0 lat: 0.0> 
 destination: <long: 1.1 lat: 1.1> 
 PROTO

  17. grpc_cli $ grpc_cli call localhost:12345 \ 
 RoutePlanner.GetRoutes \ 
 <<- PROTO 
 origin: <long: 0.0 lat: 0.0> 
 destination: <long: 1.1 lat: 1.1> 
 PROTO

  18. grpc_cli Rpc succeeded with OK status 
 Response: 
 routes: <...> 
 routes: <...> 
 routes: <...> 
 routes: <...>

  19. Service definition service RoutePlanner { rpc GetRoutes (GetRoutesRequest) returns (GetRoutesResponse) {} }

  20. Service definition - response streaming service RoutePlanner { rpc GetRoutes (GetRoutesRequest) returns ( stream GetRoutesResponse) {} }

  21. Service definition service RoutePlanner { rpc GetRoutes (GetRoutesRequest) returns (GetRoutesResponse) {} }

  22. Service definition - request streaming service RoutePlanner { rpc GetRoutes ( stream GetRoutesRequest) returns (GetRoutesResponse) {} }

  23. Request streaming? Response streaming?

  24. Request streaming? Response streaming?

Recommend


More recommend