Git Product home page Git Product logo

dubbo-py's Introduction

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])

dubbo-py's People

Contributors

feiyuw avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.