def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. with grpc.insecure_channel("localhost:50051") as channel: channel = intercept_channel(channel, client_interceptor()) stub = route_guide_pb2_grpc.RouteGuideStub(channel) # Unary print("-------------- GetFeature --------------") guide_get_feature(stub) # Server streaming print("-------------- ListFeatures --------------") guide_list_features(stub) # Client streaming print("-------------- RecordRoute --------------") guide_record_route(stub) # Bidirectional streaming print("-------------- RouteChat --------------") guide_route_chat(stub)
def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. with grpc.insecure_channel("localhost:50051") as channel: channel = intercept_channel(channel, client_interceptor()) stub = helloworld_pb2_grpc.GreeterStub(channel) # stub.SayHello is a _InterceptorUnaryUnaryMultiCallable response = stub.SayHello(helloworld_pb2.HelloRequest(name="YOU")) print("Greeter client received: " + response.message)
def setUp(self): super().setUp() self.server = create_test_server(25565) self.server.start() meter = metrics.get_meter(__name__) interceptor = client_interceptor() self.channel = intercept_channel( grpc.insecure_channel("localhost:25565"), interceptor ) self._stub = test_server_pb2_grpc.GRPCTestServerStub(self.channel) self._controller = PushController( meter, self.memory_metrics_exporter, 30 )
except (Exception, err): logger.error("could not enable debugger") logger.error(traceback.print_exc()) pass port = os.environ.get('PORT', "8080") catalog_addr = os.environ.get('PRODUCT_CATALOG_SERVICE_ADDR', '') if catalog_addr == "": raise Exception('PRODUCT_CATALOG_SERVICE_ADDR environment variable not set') logger.info("product catalog address: " + catalog_addr) # Create the gRPC client channel to ProductCatalog (server). channel = grpc.insecure_channel(catalog_addr) # OpenTelemetry client interceptor passes trace contexts to the server. channel = intercept_channel(channel, client_interceptor(trace.get_tracer_provider())) product_catalog_stub = demo_pb2_grpc.ProductCatalogServiceStub(channel) # Create the gRPC server for accepting ListRecommendations Requests from frontend (client). server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) # OpenTelemetry interceptor receives trace contexts from clients. server = intercept_server(server, server_interceptor(trace.get_tracer_provider())) # Add RecommendationService class to gRPC server. service = RecommendationService() demo_pb2_grpc.add_RecommendationServiceServicer_to_server(service, server) health_pb2_grpc.add_HealthServicer_to_server(service, server) # start server logger.info("listening on port: " + port)
def __init__(self, is_prod: bool) -> None: super().__init__() self.is_prod = is_prod self._interceptor = client_interceptor()