def run(): # channel = grpc.insecure_channel('[::]:50001') channel = grpc.insecure_channel('localhost:50051') stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name="Alex")) # response = stub.SayHello(helloworld_pb2.HelloRequest(name='czl')) # print(response.message) response = stub.SayHelloAgain(helloworld_pb2.HelloRequest(name='Nancy')) # stub.SayHelloAgain print(response.message)
def main(iterations=10, count=1000): channel = grpc.insecure_channel('127.0.0.1:50051') stub = helloworld_pb2_grpc.GreeterStub(channel) for j in range(iterations): t1 = time.time() for i in range(count): stub.SayHello(helloworld_pb2.HelloRequest(name='World')) t2 = time.time() secs = (t2 - t1) rps = int(count / (t2 - t1)) print('{} requests in {:.2f} secs ~= {} rps'.format(count, secs, rps))
def run(): channel = grpc.insecure_channel('localhost:50051') stub = helloworld_pb2_grpc.GreeterStub(channel) try: response = stub.sayHello(helloworld_pb2.HelloRequest( name='you', ver=123, bloodType="B" )) # response = stub.sayHello(helloworld_pb2.HelloRequest(ver=123)) print('greeter client received: {}'.format(response.message)) except Exception as e: print(e)
async def main(): async with grpc.aio.insecure_channel('127.0.0.1:50051') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) reply = await stub.SayHello(helloworld_pb2.HelloRequest(name='World')) print(reply)
def main(): channel = grpc.insecure_channel('127.0.0.1:50051') stub = helloworld_pb2_grpc.GreeterStub(channel) print(stub.SayHello(helloworld_pb2.HelloRequest(name='World')))
from twirp.context import Context from twirp.exceptions import TwirpServerException import sys from pathlib import Path sys.path.append(str(Path(__file__).parent.parent)) from helloworld import helloworld_pb2 from helloworld import helloworld_twirp client = helloworld_twirp.GreeterClient("http://localhost:5000") try: response = client.sayHello(ctx=Context(), request=helloworld_pb2.HelloRequest( name='you', ver=123, bloodType="B")) print(response) except TwirpServerException as e: print(e.code, e.message, e.meta, e.to_dict())
def run(): with grpc.insecure_channel(HOST + ":" + PORT) as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("over ---" + response.message)