MCPcopy Index your code
hub / github.com/apache/dubbo-python2 / DubboClient

Class DubboClient

dubbo/client.py:19–87  ·  view source on GitHub ↗

用于实现dubbo调用的客户端

Source from the content-addressed store, hash-verified

17
18
19class DubboClient(object):
20 """
21 用于实现dubbo调用的客户端
22 """
23
24 def __init__(self, interface, version='1.0.0', dubbo_version='2.4.10', zk_register=None, host=None):
25 """
26 :param interface: 接口名,例如:com.qianmi.pc.es.api.EsProductQueryProvider
27 :param version: 接口的版本号,例如:1.0.0,默认为1.0.0
28 :param dubbo_version: dubbo的版本号,默认为2.4.10
29 :param zk_register: zookeeper注册中心管理端,参见类:ZkRegister
30 :param host: 远程主机地址,用于绕过zookeeper进行直连,例如:172.21.4.98:20882
31 """
32 if not zk_register and not host:
33 raise RegisterException('zk_register和host至少需要填入一个')
34
35 logger.debug('Created client, interface={}, version={}'.format(interface, version))
36
37 self.__interface = interface
38 self.__version = version
39 self.__dubbo_version = dubbo_version
40
41 self.__zk_register = zk_register
42 self.__host = host
43
44 def call(self, method, args=(), timeout=None):
45 """
46 执行远程调用
47 :param method: 远程调用的方法名
48 :param args: 方法参数
49 1. 对于没有参数的方法,此参数不填;
50 2. 对于只有一个参数的方法,直接填入该参数;
51 3. 对于有多个参数的方法,传入一个包含了所有参数的列表;
52 4. 当前方法参数支持以下类型:
53 * bool
54 * int
55 * long
56 * float
57 * double
58 * java.lang.String
59 * java.lang.Object
60 :param timeout: 请求超时时间(秒),不设置则不会超时
61 :return:
62 """
63 if not isinstance(args, (list, tuple)):
64 args = [args]
65
66 if self.__zk_register: # 优先从zk中获取provider的host
67 host = self.__zk_register.get_provider_host(self.__interface)
68 else:
69 host = self.__host
70 # logger.debug('get host {}'.format(host))
71
72 request_param = {
73 'dubbo_version': self.__dubbo_version,
74 'version': self.__version,
75 'path': self.__interface,
76 'method': method,

Callers 7

setUpMethod · 0.90
test_auto_ruleMethod · 0.90
test_arrayMethod · 0.90
test_pcMethod · 0.90
test_pc_es_centerMethod · 0.90
test_run_defaultMethod · 0.90
test_runMethod · 0.90

Calls

no outgoing calls

Tested by 7

setUpMethod · 0.72
test_auto_ruleMethod · 0.72
test_arrayMethod · 0.72
test_pcMethod · 0.72
test_pc_es_centerMethod · 0.72
test_run_defaultMethod · 0.72
test_runMethod · 0.72