def call_average(): print("call average api") channel = grpc.insecure_channel('localhost:5555') stub = calculator_pb2_grpc.CalculatorServiceStub(channel) req_iterator = avg_iterator(5) resp = stub.Average(req_iterator) print("Average response %s" % resp.result)
def call_pnd(): print("call pnd api") channel = grpc.insecure_channel('localhost:5555') stub = calculator_pb2_grpc.CalculatorServiceStub(channel) resp = stub.PrimeNumberDecomposition(calculator_pb2.PNDRequest(number=120)) for r in resp: print("prime number: %s" % r.result)
def call_find_max(): print("call find max") channel = grpc.insecure_channel('localhost:5555') stub = calculator_pb2_grpc.CalculatorServiceStub(channel) req_iterator = find_max_iterator() responses = stub.FindMax(req_iterator) for resp in responses: print("Max response: %s" % resp.max)
def call_sum(): print("Call sum api") # with grpc.insecure_channel('localhost:5555') as channel: # stub = calculator_pb2_grpc.CalculatorServiceStub(channel) # resp = stub.Sum(calculator_pb2.SumRequest(num1=7, num2=6)) channel = grpc.insecure_channel('localhost:3333') stub = calculator_pb2_grpc.CalculatorServiceStub(channel) resp = stub.Sum(calculator_pb2.SumRequest(num1=7, num2=6)) print("sum api response: ", resp.result)
async def call_sum() -> None: print("Call sum api") channel = grpc.aio.insecure_channel('localhost:5555') stub = calculator_pb2_grpc.CalculatorServiceStub(channel) resp = await stub.Sum(calculator_pb2.SumRequest(num1=7, num2=6)) print("sum api response: ", resp.result)