{"id":14987942,"url":"https://github.com/apache/dubbo-python2","last_synced_at":"2025-12-14T14:04:45.676Z","repository":{"id":51226159,"uuid":"133488175","full_name":"apache/dubbo-python2","owner":"apache","description":"Python Dubbo Client","archived":false,"fork":false,"pushed_at":"2024-09-03T12:30:21.000Z","size":170,"stargazers_count":62,"open_issues_count":7,"forks_count":18,"subscribers_count":59,"default_branch":"master","last_synced_at":"2025-02-21T07:09:28.425Z","etag":null,"topics":["dubbo","hessian2","java-dubbo","python-dubbo"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apache.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-15T08:52:24.000Z","updated_at":"2024-12-12T02:31:22.000Z","dependencies_parsed_at":"2024-01-23T17:28:00.986Z","dependency_job_id":"c8152d92-f689-4179-9700-51b6ebb2b719","html_url":"https://github.com/apache/dubbo-python2","commit_stats":{"total_commits":161,"total_committers":5,"mean_commits":32.2,"dds":0.0496894409937888,"last_synced_commit":"de7f01433e5a40b71fd7ada229c33e1406dcce34"},"previous_names":["ritterhou/python-dubbo"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fdubbo-python2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fdubbo-python2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fdubbo-python2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fdubbo-python2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apache","download_url":"https://codeload.github.com/apache/dubbo-python2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241124181,"owners_count":19913831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dubbo","hessian2","java-dubbo","python-dubbo"],"created_at":"2024-09-24T14:15:46.181Z","updated_at":"2025-12-14T14:04:40.352Z","avatar_url":"https://github.com/apache.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# python-dubbo\n\n_Python Dubbo Client._\n\n## Installation\n\n    pip install python-dubbo\n\n## Usage\n\n#### 基础使用\n\n```python\nfrom dubbo.client import DubboClient, ZkRegister\n\n# 支持从Zk中获取服务的provider，支持根据provider的权重选择主机\nzk = ZkRegister('127.0.0.1:2181')\ndubbo_cli = DubboClient('com.qianmi.pc.api.GoodsQueryProvider', zk_register=zk)\n\n# 支持不使用Zk，直接连接指定的远程主机\ndubbo_cli = DubboClient('com.qianmi.pc.api.GoodsQueryProvider', host='127.0.0.1:20880')\n\nadmin_id = 'A000000'\nresult = dubbo_cli.call('listByIdString', admin_id)\n```\n\n#### 如何定义参数\n\npython-dubbo支持以下Java类型的参数，表格右边一列代表了在Pyton中与指定Java类型所对应的类型\n\n| 类型 | Java | Python |\n| :--- | :--- | :--- |\n| 布尔类型 | boolean | bool |\n| 整型 | int, long | int |\n| 浮点类型 | float, double | float |\n| 字符串类型 | java.lang.String | str |\n| 列表类型 | Collection \u0026 Array | [] |\n| 时间类型 | java.util.Date | datetime |\n| 自定义的对象类型 | java.lang.Object | ↓ _具体使用方法如下所示_ ↓ |\n\n##### 使用Java的对象类型\n```python\nfrom dubbo.client import DubboClient, ZkRegister\nfrom dubbo.codec.encoder import Object\n\n# 创建channel对象\nchannel = Object('com.qianmi.pc.base.api.constants.ChannelEnum', values={\n    'name': 'D2C'\n})\n\n# 创建spu_query_request对象\nspu_query_request = Object('com.qianmi.pc.item.api.spu.request.SpuQueryRequest')\nspu_query_request['chainMasterId'] = 'A000000'\nspu_query_request['channel'] = channel\nspu_query_request['pageSize'] = 2000\n\n# 创建consumer并执行查询操作\nzk = ZkRegister('172.21.4.71:2181')\nspu_query_provider = DubboClient('com.qianmi.pc.item.api.spu.SpuQueryProvider', zk_register=zk)\nresult = spu_query_provider.call('query', spu_query_request)\n```\n\n#### 如何使用枚举(enum)类型作为参数\n\n```python\n# 定义一个枚举类型的对象\nchannel = Object('com.qianmi.pc.base.api.constants.ChannelEnum')\n# 定义参数name并令其值为对应的枚举参数的值，之后使用该定义好的对象作为枚举类型变量即可\nchannel['name'] = 'D2C'\n```\n\n## Reference\n\n* Python字节相关的转化操作：\u003chttps://docs.python.org/2/library/struct.html\u003e\n* Hessian2的编码规则：\u003chttp://hessian.caucho.com/doc/hessian-serialization.html\u003e\n* 实现Hessian2编码时的参考：[参考1](https://github.com/WKPlus/pyhessian2/blob/3.1.5/pyhessian2/encoder.py)，[参考2](https://github.com/zhouyougit/PyDubbo/blob/master/dubbo/hessian2.py)\n* 对于部分不清楚且通过查阅文档仍无法了解的编码方式，先使用Java的dubbo客户端正常调用接口，之后使用[Wireshark](https://en.wikipedia.org/wiki/Wireshark)抓包获取请求和响应的数据报文，仔细的分析报文来推测编码方式\n* Dubbo相关的编码规则：[参考1](http://fe.58qf.com/2017/11/07/node-dubbo/)，[参考2](http://cxis.me/2017/03/19/Dubbo%E4%B8%AD%E7%BC%96%E7%A0%81%E5%92%8C%E8%A7%A3%E7%A0%81%E7%9A%84%E8%A7%A3%E6%9E%90/)\n* Dubbo的心跳机制：\u003chttp://www.cnblogs.com/java-zhao/p/8539046.html\u003e\n* 部分实现参考了dubbo的Java源码中的实现\n* 对于所有的字符串，在网络传输前进行编码，编码一律使用unicode来完成，如果一个字符串是str则先将其decode为unicode之后再进行操作；\n* 对于所有的字符串，在网络上获取到的数据之后进行解码，解码得到的字符串是unicode，之后将其encode为str再交给客户程序；\n* 支持传输utf-8编码和Emoji😋\n* 使用epoll模型来维护所有的链接，如果使用多线程来维护连接将产生过多的thread_context_switch，影响性能\n* 类似于HTTP请求和响应，dubbo的请求和响应也是同步的并且可以看成是一个事务；不过dubbo使用了msg_id来为请求排序，这使得我们不再需要像HTTP请求那样在单个链接上进行同步的请求和响应，因此在单个连接上有多个请求时可以一定程度的降低请求总时间，这种对请求进行编码的理念类似于[HTTP2](https://zh.wikipedia.org/wiki/HTTP/2)中的stream ID\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fdubbo-python2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapache%2Fdubbo-python2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fdubbo-python2/lists"}