Esempio n. 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--log_payloads',
        action='store_true',
        default=True,
        help='log request/response objects to open-tracing spans')
    args = parser.parse_args()

    config = Config(config={
        'sampler': {
            'type': 'const',
            'param': 1,
        },
        'logging': True,
    },
                    service_name='hello_world_client')
    tracer = config.initialize_tracer()
    tracer_interceptor = open_tracing_client_interceptor.OpenTracingClientInterceptor(
        tracer, log_payloads=args.log_payloads)
    with tracer.start_span("step1") as span:
        scope.set_active_span(span)
        time.sleep(0.01)
    channel = grpc.insecure_channel(HOST_PORT)
    channel = grpc.intercept_channel(channel, tracer_interceptor)
    stub = hello_world_pb2_grpc.GreeterStub(channel)
    response = stub.SayHello(hello_world_pb2.HelloRequest(name='you'))
    print("Message received: " + response.message)
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:8080') as channel:
        stub = hello_world_pb2_grpc.GreeterStub(channel)
        response = stub.SayHello(hello_world_pb2.HelloRequest(name='you'))
    print("Greeter client received: " + response.message)
Esempio n. 3
0
def main():
    exporter = stackdriver_exporter.StackdriverExporter()
    tracer = Tracer(exporter=exporter)
    tracer_interceptor = client_interceptor.OpenCensusClientInterceptor(
        tracer, host_port=HOST_PORT)
    channel = grpc.insecure_channel(HOST_PORT)
    channel = grpc.intercept_channel(channel, tracer_interceptor)
    stub = hello_world_pb2_grpc.GreeterStub(channel)
    response = stub.SayHello(hello_world_pb2.HelloRequest(name='you'))
    print("Message received: " + response.message)
Esempio n. 4
0
 def test_handle(self):
     input = rpc_pb2.Request()
     input.service_name = self.service.GetDescriptor().full_name
     input.method_name = 'HelloWorld'
     data = hello_world_pb2.HelloRequest()
     data.my_name = 'Zach'
     input.request_proto = data.SerializeToString()
     ret = self.handler.handle(input.SerializeToString())
     response = rpc_pb2.Response()
     response.ParseFromString(ret)
     service_res = hello_world_pb2.HelloResponse()
     service_res.ParseFromString(response.response_proto)
     self.assertEqual(service_res.hello_world, 'Hello Zach')
Esempio n. 5
0
def greet(name):
    stub = _get_grpc_stub(hello_world_pb2_grpc.GreeterStub,
                          HELLO_WORLD_HOST_PORT)
    response = stub.SayHello(hello_world_pb2.HelloRequest(name=name))
    return str(response)
Esempio n. 6
0
# Import required RPC modules
import hello_world_pb2
from protobuf.socketrpc import RpcService

# Configure logging
import logging
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

# Server details
hostname = 'localhost'
port = 8090

# Create a request
request = hello_world_pb2.HelloRequest()
request.my_name = 'Zach'

# Create a new service instance
service = RpcService(hello_world_pb2.HelloWorldService_Stub, port, hostname)


def callback(request, response):
    """Define a simple async callback."""
    log.info('Asynchronous response :' + response.__str__())


# Make an asynchronous call
try:
    log.info('Making asynchronous call')
    response = service.HelloWorld(request, callback=callback)
def run():
    channel = grpc.insecure_channel('localhost:50051')
    stub = hello_world_pb2_grpc.GreeterStub(channel)
    response = stub.SayHello(hello_world_pb2.HelloRequest(name='you'))
    print("Greeter client received: " + response.message)