예제 #1
0
def run():
    with grpc.insecure_channel('localhost:50051') as channel:
        stub = hello_pb2_grpc.HelloStub(channel)
        # for message in messages:
        messages_ = get_input()
        for message in messages_:
            greet_with_message(stub,
                               name=message['name'],
                               message=message['message'])
예제 #2
0
def test_stream_stream(grpc_server, grpc_resolver, messages):
    channel = RoundrobinChannel('grpcresolver.hello.Hello', grpc_resolver)
    stub = hello_pb2_grpc.HelloStub(channel)

    request = (hello_pb2.HelloRequest(message=message) for message in messages)
    response_iter = stub.StreamGreeterResponseStream(request)

    for response in response_iter:
        assert response.message
예제 #3
0
def test_stream_unary(grpc_server, grpc_resolver, messages, future):
    channel = RoundrobinChannel('grpcresolver.hello.Hello', grpc_resolver)
    stub = hello_pb2_grpc.HelloStub(channel)

    request = (hello_pb2.HelloRequest(message=message) for message in messages)
    if future:
        response = stub.StreamGreeter.future(request).result()
    else:
        response = stub.StreamGreeter(request)

    assert response.message
예제 #4
0
import grpc

import hello_pb2
import hello_pb2_grpc

channel = grpc.insecure_channel('localhost:50051')
stub = hello_pb2_grpc.HelloStub(channel)

request = hello_pb2.HelloRequest(value="World")
response = stub.Hello(request)

print(response.value)
예제 #5
0
 def __init__(self, host='localhost', port=5002):
     self.host = host
     self.port = port
     self.channel = grpc.insecure_channel(f'{self.host}:{self.port}')
     self.stub = hello_pb2_grpc.HelloStub(self.channel)
예제 #6
0
def run():
    with grpc.insecure_channel('localhost:50051') as channel:
        stub = hello_pb2_grpc.HelloStub(channel)
        response = stub.sayHello(hello_pb2.HelloRequest(name='you'))
    print("Hello client received: " + response.message)