14 """The Python AsyncIO implementation of the gRPC route guide client."""
19 from typing
import Iterable, List
22 import route_guide_pb2
23 import route_guide_pb2_grpc
24 import route_guide_resources
28 longitude: int) -> route_guide_pb2.RouteNote:
36 point: route_guide_pb2.Point) ->
None:
37 feature = await stub.GetFeature(point)
38 if not feature.location:
39 print(
"Server returned incomplete feature")
43 print(f
"Feature called {feature.name} at {feature.location}")
45 print(f
"Found no feature at {feature.location}")
57 stub: route_guide_pb2_grpc.RouteGuideStub) ->
None:
61 print(
"Looking for features between 40, -75 and 42, -73")
63 features = stub.ListFeatures(rectangle)
65 async
for feature
in features:
66 print(f
"Feature called {feature.name} at {feature.location}")
70 feature_list: List[route_guide_pb2.Feature]
71 ) -> Iterable[route_guide_pb2.Point]:
72 for _
in range(0, 10):
73 random_feature = random.choice(feature_list)
74 print(f
"Visiting point {random_feature.location}")
75 yield random_feature.location
85 route_summary = await stub.RecordRoute(route_iterator)
86 print(f
"Finished trip with {route_summary.point_count} points")
87 print(f
"Passed {route_summary.feature_count} features")
88 print(f
"Travelled {route_summary.distance} meters")
89 print(f
"It took {route_summary.elapsed_time} seconds")
101 print(f
"Sending {msg.message} at {msg.location}")
110 async
for response
in call:
111 print(f
"Received message {response.message} at {response.location}")
115 async
with grpc.aio.insecure_channel(
'localhost:50051')
as channel:
117 print(
"-------------- GetFeature --------------")
119 print(
"-------------- ListFeatures --------------")
121 print(
"-------------- RecordRoute --------------")
123 print(
"-------------- RouteChat --------------")
127 if __name__ ==
'__main__':
128 logging.basicConfig(level=logging.INFO)
129 asyncio.get_event_loop().run_until_complete(
main())