Skip to main content

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 调用更简单 🚀

Metadata

Release files for yz-dubbo 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yz-dubbo 0.1.4
File Size Uploaded
yz_dubbo-0.1.4.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yz-dubbo 0.1.4
File Interpreter ABI Platform
yz_dubbo-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / yz_dubbo-0.1.4.tar.gz

Download URL yz_dubbo-0.1.4.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
653727b562fe018ed0fb8609f9f0a6d9d7ddfed5bcb0af8119542df038ed8ff5
BLAKE2b-256 checksum
How to use checksums
f5dd1887160b56e0d11512b7a157dee0e36907f15c1d362808c7a55d244bafd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / yz_dubbo-0.1.4-py3-none-any.whl

Download URL yz_dubbo-0.1.4-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1dfc3e7c2f5ff55709eebe33db06b870acb02c56bfa70bd6a524bdf14b1d4576
BLAKE2b-256 checksum
How to use checksums
13677783869047ab22748267daa5bd21fcd301e57c3ebff26e0082fa34181f30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page