示例#1
0
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)
示例#2
0
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)
示例#3
0
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)
示例#4
0
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)
示例#5
0
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)