def getRecord(): with grpc.insecure_channel('172.16.1.176:50052') as channel: stub = bank_pb2_grpc.bankStub(channel) # response = stub.balance(bank_pb2.balanceRequest(account='yl001')) # print(response) responses = stub.getRecord(bank_pb2.getRecordRequest(account='yl001')) for response in responses: print(response)
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('127.0.0.1:50052') as channel: stub = bank_pb2_grpc.bankStub(channel) response = stub.deposit( bank_pb2.depositRequest(account='yl001', value=100)) print("depositRequest : account='yl001',value=100") print("received : " + response.message + ", " + str(response.balance) + ", " + str(response.recordIndex)) print("-------------------------------------------") response = stub.withdrawal( bank_pb2.withdrawalRequest(account='yl001', value=100)) print("withdrawalRequest : account='yl001',value=100") print("received : " + response.message + ", " + str(response.balance) + ", " + str(response.recordIndex)) print("-------------------------------------------") response = stub.balance(bank_pb2.balanceRequest(account='yl001')) print("balanceRequest : account='yl001'") print("received : " + response.message + ", " + str(response.balance)) print("-------------------------------------------") response = stub.deposit( bank_pb2.depositRequest(account='yl002', value=100)) print("depositRequest : account='yl002',value=100") print("received : " + response.message + ", " + str(response.balance) + ", " + str(response.recordIndex)) print("-------------------------------------------") response = stub.transfer( bank_pb2.transferRequest(fromAccount='yl001', toAccount='yl002', value=100)) print( "transferRequest : fromAccount='yl001',toAccount='yl002',value=100" ) print("received : " + response.message + ", " + str(response.balance) + ", " + str(response.recordIndex)) print("-------------------------------------------") response = stub.balance(bank_pb2.balanceRequest(account='yl001')) print("balanceRequest : account='yl001'") print("received : " + response.message + ", " + str(response.balance)) print("-------------------------------------------") response = stub.balance(bank_pb2.balanceRequest(account='yl002')) print("balanceRequest : account='yl002'") print("received : " + response.message + ", " + str(response.balance)) print("-------------------------------------------")
def run1000_1(): with grpc.insecure_channel('172.16.1.176:50052') as channel: stub = bank_pb2_grpc.bankStub(channel) for i in range(1000): response = stub.deposit( bank_pb2.depositRequest(account='yl001', value=2)) if (i % 100 == 0): print("run...run1000_1") response = stub.balance(bank_pb2.balanceRequest(account='yl001')) print("balanceRequest : account='yl001'") print("received : " + response.message + ", " + str(response.balance)) print("-------------------------------------------")
def bank_client(BANK_SERVER): with grpc.insecure_channel(BANK_SERVER) as channel: stub = bank_pb2_grpc.bankStub(channel) return stub return None