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 wrapper_fn(self, exporter, interval, original_func, instance, args,
                kwargs):
     channel = original_func(*args, **kwargs)
     tracer_provider = kwargs.get("tracer_provider")
     return intercept_channel(
         channel,
         client_interceptor(
             tracer_provider=tracer_provider,
             exporter=exporter,
             interval=interval,
         ),
     )
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)
Exemple #6
0
 def wrapper_fn(self, original_func, instance, args, kwargs):
     with original_func(*args, **kwargs) as channel:
         yield intercept_channel(channel, client_interceptor())
Exemple #7
0
 def _service_channel(self, service_name: util.ServiceName) -> grpc.Channel:
     with grpc.insecure_channel(
             util.address_for_client(service_name,
                                     self.is_prod)) as channel:
         yield intercept_channel(channel, self._interceptor)