Python client for Apache Dubbo RPC protocol, with Hessian2 serialization and SSL/TLS support.
Project description
dubbo-ssl-python
Python client for Apache Dubbo RPC protocol. Implements the dubbo wire protocol (16-byte header with magic 0xdabb) + Hessian2 serialization,enabling Python application to invoke Java Dubbo 2.x services directly. Support TCP,SSL/TLS connections,Zookeeper services discovery.
Base on https://github.com/apache/dubbo-python2 and https://github.com/huisongyang/dubbo-python3, support Python3.
Features
- Full Hessian2 serialization/deserialization (primitives, objects, lists, maps, dates, null, circular references)
- TCP and SSL/TLS connections with custom CA certificate support
- Zookeeper-based services discovery with weighted load balancing
- Connection pooling with automatic heartbeat and reconnection
- Support
groupsettings for Dubbo, Compatible with Dubbo 2.x
Requirements
- Python3.8+
- kazoo. --Zookeeper client (required only if using ZkRegister)
Installation
pip install dubbo-ssl-python
Dependencies:
kazoo-- Zookeeper client for service discovery
Quick start
Direct Connection (TCP)
Connect to a Dubbo service without Zookeeper:
from dubbo_ssl.client import DubboClient
from dubbo_ssl.codec.encoder import Object
client = DubboClient(
interface="com.example.service.UserService",
group="default",
version="1.0.0",
dubbo_version="2.7.23",
host="127.0.0.1:20880",
verify=None # Plain TCP,no SSL
)
request = Object("com.example.service.UserService.dto.UserRequest")
request["userId"] = "A000021"
request["type"] = "QUERY"
result = client.call(method="getUser",args=request)
print(request)
SSL/TLS Connection
Connect to a Dubbo service over SSL with custom CA certificate verification:
from dubbo_ssl.client import DubboClient
client = DubboClient(
interface="com.example.service.UserService",
group="default",
version="1.0.0",
dubbo_version="2.7.23",
host="127.0.0.1:20880",
verify="/path/to/DubboRootCA.cer" # Custom CA certificate file
)
request = " Hello, SSL Provider."
result = client.call(method="getUser",args=request)
print(request)
The verify parameter supports three SSL models:
| Value | Behavior |
|---|---|
None |
Plain TCP,no SSL |
"/path/to/ca.crt" |
SSL with custom CA certificate verification, hostname check disabled |
False |
SSL with no server certificate verification (insecure) |
Zookeeper Service discovery
Use Zookeeper for automatic service discovery and load balancing:
from dubbo_ssl.client import DubboClient, ZkRegister
zk = ZkRegister(hosts="127.0.0.1:2181", application_name="MyAPP")
client = DubboClient(
interface="com.example.service.UserService",
group="default",
version="1.0.0",
dubbo_version="2.7.23",
zk_register=zk
)
request = " Hello, SSL Provider."
result = client.call(method="getUser",args=request)
# When done
zk.close()
Multiple Arguments
Pass multiple arguments to a method
result = client.call(
method="query",
args=["keyword",10,5]
)
Custom Context (Attachments)
Pass RPC attachment metadata ( key-value pairs sent alongside the request)
result = client.call(
method="getRequest",
args=["keyword",10,5],
context={"traceId":"x-123","tenantId":"T001"}
)
Timeout
Set a request timeout in seconds.
result = client.call(
method="getRequest",
args=["keyword"],
timeout=5
)
Type Mapping
Python -> Java (Request Encoding)
| Python Type | Java Type | Hessian2 Code | Note |
|---|---|---|---|
bool |
boolean |
T/ F |
|
int (within int32 range) |
int |
Compact I encoding |
-2^31 ~ 2^31-1 |
int (exceed int32) |
long |
L (8-byte) |
|
float |
double |
Compact D encoding |
Includes 0.0/1.0 short forms |
str |
java.lang.String |
Short S encoding |
UTF-8 |
Object |
Java class | C + O |
Class definition + instance |
list |
Java array | Typed list encoding | Elements must be same type; empty list -> null |
None |
null | N |
Java -> Python (Response Decoding)
| Java Type | Python Type | Hessian2 Code |
|---|---|---|
boolean |
boolean |
T/ F |
int |
int |
Compact I / I (4-byte) |
long |
int |
Compact / L (8-byte) |
double |
float |
Compact D / D (8-byte IEEE 754) |
java.lang.String |
str |
Short / chunked S / R |
| java object | dict |
C + O (field names as keys) |
java.math.BigDecimal |
float |
Auto-converted from value field |
java.math.BigInteger |
int |
Auto-converted from value field |
| List / array | list |
Type / untyped, fixed / variable length |
| Map | dict |
M / H (untyped) |
java.util.Date |
str |
ISO 8601 format string |
null |
None |
N |
| Circular reference | resolved | Q (ref) |
License
Apache License 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 dubbo_ssl_python-0.9.6.tar.gz.
File metadata
- Download URL: dubbo_ssl_python-0.9.6.tar.gz
- Upload date:
- Size: 26.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2ef606716267b2de36ea08497394e96598fcedc0fabf05e93be96b530fe0105
|
|
| MD5 |
472f41b1ba7ff14d6b7a6cae09fd5de0
|
|
| BLAKE2b-256 |
80b89e4dbce84aba541a0b58a203b41f48ac0ca9bdc14f06d15caea01383c891
|
File details
Details for the file dubbo_ssl_python-0.9.6-py3-none-any.whl.
File metadata
- Download URL: dubbo_ssl_python-0.9.6-py3-none-any.whl
- Upload date:
- Size: 26.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65ddf1689722a4d5b7a2d3eff8b56902e4b78becff257ae2bb3bd05608d8c9e5
|
|
| MD5 |
fcb3408420b48c13dc37d29930389c24
|
|
| BLAKE2b-256 |
b8a2436b876977be950009fa325646923f0272bfbae9cfa738548aab8db28aee
|