Skip to main content

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 group settings 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dubbo_ssl_python-0.9.2.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dubbo_ssl_python-0.9.2-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

Details for the file dubbo_ssl_python-0.9.2.tar.gz.

File metadata

  • Download URL: dubbo_ssl_python-0.9.2.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for dubbo_ssl_python-0.9.2.tar.gz
Algorithm Hash digest
SHA256 ce525db147bc09dfc90f990154548eed2048735aaebfe79ad5df569bbc7c02f1
MD5 0424c47ffab144eb27b15eedc581f963
BLAKE2b-256 3af3983f98b4799c1fcec88f305bc964e26e93aac1c6d16b91b89759ee182271

See more details on using hashes here.

File details

Details for the file dubbo_ssl_python-0.9.2-py3-none-any.whl.

File metadata

File hashes

Hashes for dubbo_ssl_python-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b802826a9aaebacac8431c0793629bc0f058018f792049ff5a591fec926f1b7b
MD5 e8ae990e9c6c39ce4551a2b8287f36cb
BLAKE2b-256 b34a01049ea2b866238228fc71f6c825aa2faf73b251657cf436636742d11dc1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page