commit | 4c75398746ca68558abd1a6de9b37057bb2492cd | [log] [tgz] |
---|---|---|
author | 侯锐 <hourui@qianmi.com> | Fri Jul 20 16:59:23 2018 +0800 |
committer | 侯锐 <hourui@qianmi.com> | Fri Jul 20 16:59:23 2018 +0800 |
tree | c23e56473003a4ccd1542b8a64b3d50c43ae29e1 | |
parent | c73afb648379768ca2b34ab8d0d201ffaf001e9e [diff] |
更新版本
Python Dubbo Client.
pip install python-dubbo
from dubbo.client import DubboClient, ZkRegister # 支持从Zk中获取服务的provider,支持根据provider的权重选择主机 zk = ZkRegister('127.0.0.1:2181') dubbo_cli = DubboClient('com.qianmi.pc.api.GoodsQueryProvider', zk_register=zk) # 支持不使用Zk,直接连接指定的远程主机 dubbo_cli = DubboClient('com.qianmi.pc.api.GoodsQueryProvider', host='127.0.0.1:20880') admin_id = 'A000000' result = dubbo_cli.call('listByIdString', admin_id)
python-dubbo支持以下Java类型的参数,表格右边一列代表了在Pyton中与指定Java类型所对应的类型
类型 | Java | Python |
---|---|---|
布尔类型 | boolean | bool |
整型 | int, long | int |
浮点类型 | float, double | float |
字符串类型 | java.lang.String | str |
列表类型 | Collection & Array | [] |
自定义的对象类型 | java.lang.Object | ↓ 具体使用方法如下所示 ↓ |
from dubbo.client import DubboClient, ZkRegister from dubbo.codec.encoder import Object # 创建channel对象 channel = Object('com.qianmi.pc.base.api.constants.ChannelEnum', values={ 'name': 'D2C' }) # 创建spu_query_request对象 spu_query_request = Object('com.qianmi.pc.item.api.spu.request.SpuQueryRequest') spu_query_request['chainMasterId'] = 'A000000' spu_query_request['channel'] = channel spu_query_request['pageSize'] = 2000 # 创建consumer并执行查询操作 zk = ZkRegister('172.21.4.71:2181') spu_query_provider = DubboClient('com.qianmi.pc.item.api.spu.SpuQueryProvider', zk_register=zk) result = spu_query_provider.call('query', spu_query_request)
# 定义一个枚举类型的对象 channel = Object('com.qianmi.pc.base.api.constants.ChannelEnum') # 定义参数name并令其值为对应的枚举参数的值,之后使用该定义好的对象作为枚举类型变量即可 channel['name'] = 'D2C'