有赞 Dubbo SDK - 支持 Dubbo RPC 调用
Project description
YZ-Dubbo
有赞 Dubbo SDK - 基于 Tether 网关的 Dubbo RPC 调用封装
功能特性
- 🚀 简单易用: 提供简洁的函数式 API
- ⏱️ 超时控制: 支持自定义超时时间,默认3秒
安装
pip install yz-dubbo
快速开始
基础调用
from yz_dubbo import invoke
# 调用 Dubbo 服务
result = invoke(
service_name="com.youzan.service.UserService",
method_name="getUserInfo",
args=[{"userId": 123}]
)
print(result) # 直接返回响应数据
自定义 Headers
result = invoke(
service_name="com.youzan.service.OrderService",
method_name="createOrder",
args=[{"productId": 456, "quantity": 1}],
headers={
"X-Request-Id": "req-123",
"X-Tenant-Id": "tenant-456"
}
)
设置超时时间
result = invoke(
service_name="com.youzan.service.PaymentService",
method_name="pay",
args=[payment_data],
timeout=10000 # 10秒超时
)
错误处理
错误码对照表
| 错误码 | 说明 | 错误信息 |
|---|---|---|
10000001 |
网络超时 | NETWORK_TIMEOUT |
10000002 |
网络错误 | NETWORK_ERROR |
10000003 |
参数不能为空 | PARAMS_EMPTY_ERROR |
10000004 |
服务接口错误 | SERVICE_INTERFACE_ERROR |
异常处理示例
from yz_dubbo import invoke, YzDubboException, YzDubboErrorCode
try:
result = invoke(
service_name="com.youzan.service.UserService",
method_name="getUser",
args=[{"userId": 123}]
)
print(f"成功: {result}")
except YzDubboException as e:
print(f"错误码: {e.code}")
print(f"错误信息: {e.message}")
print(f"上下文: {e.context}")
# 根据错误码处理
if e.code == YzDubboErrorCode.NETWORK_TIMEOUT.code:
print("请求超时,请稍后重试")
elif e.code == YzDubboErrorCode.NETWORK_ERROR.code:
print("网络错误")
else:
print("其他错误")
许可证
MIT License
联系方式
- 项目地址:
/packages/yz_dubbo - 测试目录:
/tests/yz_dubbo
YZ-Dubbo - 让 Dubbo 调用更简单 🚀
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yz_dubbo-0.1.4.tar.gz
(5.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yz_dubbo-0.1.4.tar.gz.
File metadata
- Download URL: yz_dubbo-0.1.4.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
653727b562fe018ed0fb8609f9f0a6d9d7ddfed5bcb0af8119542df038ed8ff5
|
|
| MD5 |
ee9061e05536b859a07f66fb8d5b02b3
|
|
| BLAKE2b-256 |
f5dd1887160b56e0d11512b7a157dee0e36907f15c1d362808c7a55d244bafd8
|
File details
Details for the file yz_dubbo-0.1.4-py3-none-any.whl.
File metadata
- Download URL: yz_dubbo-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dfc3e7c2f5ff55709eebe33db06b870acb02c56bfa70bd6a524bdf14b1d4576
|
|
| MD5 |
11e1dafd06118aa320a2b916d15e7d52
|
|
| BLAKE2b-256 |
13677783869047ab22748267daa5bd21fcd301e57c3ebff26e0082fa34181f30
|