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'])
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
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
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)
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)
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)