Skip to main content

dubbo adaptor for python

Project description

dubbo-py 是一个用Python3进行dubbo协议编解码和service、client模拟的Library,开发它的目的是用于对现有dubbo服务进行功能自动化测试,包括模拟dubbo的provider和consumer。

Build Status

Install

pip3 install dubbo-py

Example

# 作为Server
from dubbo.codec.hessian2 import DubboResponse
from dubbo.server import DubboService


def remote_max(nums):
    return max(nums)


def remote_divide(a, b):
    return a / b


service = DubboService(12358, 'demo')
service.add_method('com.myservice.math', 'max', remote_max)
service.add_method('com.myservice.math', 'divide', remote_divide)
# service.register('127.0.0.1:2181', '1.0.0')  # register to zookeeper
service.start()  # service run in a daemon thread


# 作为Client
from dubbo.client import DubboClient


client = DubboClient('127.0.0.1', 12358)
resp = client.send_request_and_return_response(service_name='com.myservice.math', method_name='max', args=[[1, 2, 3, 4]])
print(resp.ok)   # True
print(resp.data)  # 4
print(resp.error)  # None

resp = client.send_request_and_return_response(service_name='com.myservice.math', method_name='divide', args=[1, 0])
print(resp.ok)   # False
print(resp.data)  # None
print(resp.error)  # division by zero

也可以构造Java Object来请求,如:

# client
from dubbo.codec.hessian2 import new_object
from dubbo.client import DubboClient

client = DubboClient('127.0.0.1', 12358)
# 构造一个Java Object为com.demo.test的参数
arg = new_object(
    'com.demo.test',
    uuid='1b7530ba-2afa-4e7f-9876-c6744831c3fd',
    id=10,
    key='helloEvt',
    param={'name': 'hello', 'value': 'world'},
    doit=True)
resp = client.send_request_and_return_response(
    service_name='com.myservice.complex',
    method_name='aggr',
    args=[arg])

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-py-0.2.2.tar.gz (12.2 kB view details)

Uploaded Source

File details

Details for the file dubbo-py-0.2.2.tar.gz.

File metadata

  • Download URL: dubbo-py-0.2.2.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/2.7.16

File hashes

Hashes for dubbo-py-0.2.2.tar.gz
Algorithm Hash digest
SHA256 18e073dcffb8e2dca363adcc6fb4fcc33de0f869862581b9100edd328520bb56
MD5 1c7beb214a983ddd0f9cac7c042acfee
BLAKE2b-256 a48a3c52e5e64cde4fe1d0c09a92a1bcd09be9cce244448a694efa63108c3011

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