def run(): with grpc.insecure_channel('localhost:50051') as channel: stub = pbg.GreeterStub(channel) hello_request = pb.HelloRequest(name='you') response = stub.SayHello(hello_request) response = stub.SayHelloAgain(hello_request) print("Greeter client 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:50051') as channel: stub = greeter_pb2_grpc.GreeterStub(channel) response = stub.SayHello(greeter_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message)
def say_hello(index): for i in range(1): response = BaseClient( host='127.0.0.1', port='50051', stub_class=pb2_grpc.GreeterStub, ).execute( call_func='SayHello', data={'request': pb2.HelloRequest(name='Jerry')}, )
def say_hello_context_way(index): with ChannelManager(address='127.0.0.1:50051', options=options) as channel_manager: for i in range(1): response = ChannelClient( channel=channel_manager.instance, stub_class=pb2_grpc.GreeterStub, ).execute( call_func='SayHello', data={'request': pb2.HelloRequest(name='Jerry' * 100000)}, )
def say_hello_generic_way(index): channel_manager = ChannelManager(address='127.0.0.1:50051', options=options) response = ChannelClient( channel=channel_manager.instance, stub_class=pb2_grpc.GreeterStub, ).execute( call_func='SayHello', data={'request': pb2.HelloRequest(name='Jerry')}, ) print(response) channel_manager.release()
def _name_generator(): names = ('Foo', 'Bar', 'Bat', 'Baz') for name in names: yield greeter_pb2.HelloRequest(name=name) sleep(0.5)
import greeter_pb2 def _name_generator(): names = ('Foo', 'Bar', 'Bat', 'Baz') for name in names: yield greeter_pb2.HelloRequest(name=name) sleep(0.5) if __name__ == '__main__': channel = grpc.insecure_channel('127.0.0.1:50051') stub = greeter_pb2.GreeterStub(channel) response = stub.SayHello(greeter_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message) response_iterator = stub.SayHelloGoodbye( greeter_pb2.HelloRequest(name="y'all")) for response in response_iterator: print(response.message) response_iterator = stub.SayHelloToMany(_name_generator()) for response in response_iterator: print(response.message) response = stub.SayHelloToManyAtOnce(_name_generator()) print(response.message)
import grpc import greeter_pb2 import greeter_pb2_grpc # Run Client if __name__ == '__main__': with grpc.insecure_channel('localhost:50051') as channel: # Read server stub stub = greeter_pb2_grpc.GreeterStub(channel) # Make a gRPC call/request to SayHello function response = stub.SayHello(greeter_pb2.HelloRequest(name='Lukasz')) print("Greeter client received: " + response.message) # # Make a gRPC call/request to SayHelloAgain function # response = stub.SayHelloAgain(greeter_pb2.HelloRequest(name='Lukasz')) # print("Greeter client received: " + response.message)
def main(): with grpc.insecure_channel("localhost:8081") as channel: stub = greeter_pb2_grpc.GreeterStub(channel) resp = stub.SayHello(greeter_pb2.HelloRequest(name="HoHoHo")) print(resp.message)
def hello(name): requests_total.inc() response = greeter_client.SayHello( greeter_pb2.HelloRequest(name=name, age=1)) return response.message
def run(): with grpc.insecure_channel('localhost:8000') as channel: stub = greeter_pb2_grpc.GreeterStub(channel) response = stub.SayHello(greeter_pb2.HelloRequest(name='you')) print('Greeter client received: ' + response.message)