def create_client(): client = TcpRpcClient('127.0.0.1', 10017, timeout=2) resp = client.call('sayHello', 'xiaoming') self.assertEqual(resp, 'hello xiaoming') time.sleep(10) resp = client.call('sayHello', 'zhangsan') self.assertEqual(resp, 'hello zhangsan')
def create_client(): client = TcpRpcClient('127.0.0.1', 10019, timeout=2) name = ''.join([ random.choice('abcdefghijklmnopqrstuvwxyz') for i in range(2000) ]) resp = client.call('sayHello', name) self.assertEqual(resp, 'hello ' + name)
def create_client(): from agileutil.rpc.client import TcpRpcClient client = TcpRpcClient('127.0.0.1', 10017, timeout=2) resp = client.call('sayHello', ('xiaoming')) self.assertEqual(resp, 'hello xiaoming') time.sleep(10) resp = client.call('sayHello', ('zhangsan')) self.assertEqual(resp, 'hello zhangsan')
def create_client(): cli = TcpRpcClient() disconf = DiscoveryConfig(consulHost=CONSUL_HOST, consulPort=CONSUL_PORT, serviceName='test-rpc-server') cli.setDiscoveryConfig(disconf) for i in range(3): resp = cli.call('sayHello', 'mary') self.assertEqual(resp, 'hello mary')
def create_client(): client = TcpRpcClient(servers=[ '127.0.0.1:10005', '127.0.0.1:10006', '127.0.0.1:10007', ]) for i in range(10): resp = client.call('sayHello', 'zhangsan') self.assertEqual(resp, 'hello zhangsan')
def create_client(): from agileutil.rpc.client import TcpRpcClient client = TcpRpcClient(servers=[ '127.0.0.1:10005', '127.0.0.1:10006', '127.0.0.1:10007', ]) for i in range(10): resp = client.call(func='sayHello', args=('zhangsan', )) self.assertEqual(resp, 'hello zhangsan')
def create_client(): from agileutil.rpc.client import TcpRpcClient from agileutil.rpc.discovery import DiscoveryConfig cli = TcpRpcClient() disconf = DiscoveryConfig(consulHost=CONSUL_HOST, consulPort=CONSUL_PORT, serviceName='test-rpc-server') cli.setDiscoveryConfig(disconf) for i in range(3): resp = cli.call(func='sayHello', args=('mary')) self.assertEqual(resp, 'hello mary')
def create_client(): client = TcpRpcClient('127.0.0.1', 10014, timeout=2) tag = '' try: resp = client.call('testTimeout') self.assertEqual(resp, 'finish') except socket.timeout as ex: tag = 'test timeout ok!' self.assertEqual(tag, 'test timeout ok!') resp = client.call('sayHello', 'xiaoming') self.assertEqual(resp, 'hello xiaoming')
from agileutil.rpc.client import TcpRpcClient from conf.config import disconf from utils.server_register import Myconsul #rpc客户端连接实例 cli = TcpRpcClient() #配置中心连接 session = Myconsul() #rpc实例使用配置中心配置 cli.setDiscoveryConfig(disconf) print('#######################场景使用示例#############################') #获取活跃的服务信息 print('1:活跃的微服务名\n', session.get_active_service()) #获取全部的服务信息 print('2:全部的微服务信息\n', session.get_all_service()) #获取相应服务的配置信息 print('3:查询微服务配置信息\n', session.get('cmdb-report-service')) #微服务远程调用 print('4:微服务函数调度方式\n', cli.call('sum', 1, 4)) print(cli.call('hello')) print('5:远程调度类方法') print(cli.call('CmdbService.get')) # print('5:调用类方法\n',cli.call('CmdbService.get'))
#coding=utf-8 from agileutil.rpc.client import TcpRpcClient c = TcpRpcClient('127.0.0.1', 9988) resp = c.call(func='sayHello', args=('xiaoming')) print('resp', resp)
def create_client(): client = TcpRpcClient('127.0.0.1', 9988) for i in range(3): resp = client.call('sayHello', 'zhangsan') self.assertEqual(resp, 'hello zhangsan')
def create_client(): client = TcpRpcClient('127.0.0.1', 10022, timeout=2) resp = client.call('TestService.add', n1=1, n2=2) self.assertEqual(resp, 3)
def create_client(): from agileutil.rpc.client import TcpRpcClient client = TcpRpcClient('127.0.0.1', 10018, timeout=2) resp = client.call('add', (1, 1)) self.assertEqual(resp, 2)
def create_client(): client = TcpRpcClient('127.0.0.1', 10018, timeout=2) resp = client.call('add', n1=1, n2=1) self.assertEqual(resp, 2)
def create_client(): from agileutil.rpc.client import TcpRpcClient client = TcpRpcClient('127.0.0.1', 9988) for i in range(3): resp = client.call(func='sayHello', args=('zhangsan', )) self.assertEqual(resp, 'hello zhangsan')
def create_client(): from agileutil.rpc.client import TcpRpcClient client = TcpRpcClient('127.0.0.1', 10004) for i in range(3): resp = client.call(func='retObj') self.assertEqual(resp.val, 10)
def create_client(): client = TcpRpcClient('127.0.0.1', 10004) for i in range(3): resp = client.call('retObj') self.assertEqual(resp.val, 10)