Skip to main content
# Doge


[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/zhu327/doge/blob/master/LICENSE)
[![Build Status](https://travis-ci.org/zhu327/doge.svg?branch=master)](https://travis-ci.org/zhu327/doge)
[![codecov](https://codecov.io/gh/zhu327/doge/branch/master/graph/badge.svg)](https://codecov.io/gh/zhu327/doge)

Doge is a Python RPC framework like [Alibaba Dubbo](http://dubbo.io/) and [Weibo Motan](https://github.com/weibocom/motan).

## Features

![doge](https://camo.githubusercontent.com/51ff9a1d5530f269f3074e9172483acf14c73eb8/687474703a2f2f6e2e73696e61696d672e636e2f746563682f7472616e73666f726d2f32303136303531302f4a7458792d66787279686875323338323938372e6a7067)

- 服务治理, 服务注册, 服务发现
- 高可用策略, failover, backupRequestHA
- 负载均衡策略, RandomLB, RoundrobinLB
- 限流策略, gevent Pool

## Quick Start

### Installation

```sh
pip install dogerpc
```

你可以在[examples](https://github.com/zhu327/doge/tree/master/examples)找到以下实例

### Doge server

1. 新建server端配置文件

```javascript
{
"registry": { // 注册中心
"protocol": "etcd", // 注册协议, 支持 etcd 与 direct, 默认 etcd
"host": "127.0.0.1", // 注册中心 host
"port": 2379, // 注册中心 port
// "address": "127.0.0.1:2379,127.0.0.1:4001", // 注册中心地址, 如果有etcd集群, 可配置多个node
"ttl": 10 // etcd注册ttl, 用于server的心跳检查, 默认10s
},
"service": {
"name": "test", // 服务名称
"node": "n1", // 节点名称
"host": "127.0.0.1", // 服务暴露ip
"port": 4399, // 服务暴露port
"limitConn": 100 // 服务最大连接数, 可选, 默认不限制
}
}
```

2. 定义RPC methods类, 启动服务

```python
# coding: utf-8

from gevent import monkey
monkey.patch_socket() # 依赖gevent

import logging
logging.basicConfig(level=logging.DEBUG)

from doge.rpc.server import new_server


# 定义rpc方法类
class Sum(object):
def sum(self, x, y):
return x + y


if __name__ == '__main__':
server = new_server('server.json') # 基于配置文件实例化server对象
server.load(Sum) # 加载暴露rpc方法类
server.run() # 启动服务并注册节点信息到注册中心
```

### Doge client

1. 新建client端配置文件

```javascript
{
"registry": { // 注册中心
"protocol": "etcd", // 注册协议, 支持 etcd 与 direct, 默认 etcd
"host": "127.0.0.1", // 注册中心 host
"port": 2379, // 注册中心 port
// "address": "127.0.0.1:2379,127.0.0.1:4001", // 注册中心地址, 如果有etcd集群, 可配置多个node
"ttl": 10 // etcd注册ttl, 用于server的心跳检查, 默认10s
},
"refer": {
"haStrategy": "failover", // 高可用策略, 支持 failover backupRequestHA, 默认failover
"loadbalance": "RoundrobinLB", // 负载均衡策略, 支持 RandomLB RoundrobinLB, 默认RoundrobinLB
}
}
```

2. 创建client并call远程方法

```python
# coding: utf-8

from __future__ import print_function

from gevent import monkey
monkey.patch_socket()

import logging
logging.basicConfig(level=logging.DEBUG)

from doge.rpc.client import Cluster

if __name__ == '__main__':
cluster = Cluster('client.json') # 基于配置文件实例化Cluster对象
client = cluster.get_client("test") # 获取服务名对应的Client对象
print(client.call('sum', 1, 2)) # 远程调用服务Sum类下的sum方法
```

## doge json gateway

基于Bottle实现的json rpc gateway

<https://gist.github.com/zhu327/24c8262dc40c5de7eeaddbfc572f4215>

## Requirements

- [gevent](https://github.com/gevent/gevent)
- [mprpc](https://github.com/studio-ousia/mprpc)
- [python-etcd](https://github.com/jplana/python-etcd)
- [pyformance](https://github.com/omergertel/pyformance)

## License

Apache License, Version 2.0

Metadata

Release files for dogerpc 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 dogerpc 0.1.4
File Size Uploaded Provenance Actions
dogerpc-0.1.4.tar.gz 11.5 kB Without provenance Details for dogerpc-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dogerpc 0.1.4
File Interpreter ABI Platform Actions
dogerpc-0.1.4-py2.py3-none-any.whl Python 3, Python 2 none any Details for dogerpc-0.1.4-py2.py3-none-any.whl

Total release size: 27.2 kB

Release files / dogerpc-0.1.4.tar.gz

Download URL dogerpc-0.1.4.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5c2721148c729105d634e1a9800e3aaad16586d690c5e8d249c2b95adf2a992f
BLAKE2b-256 checksum
How to use checksums
882074c2e58d25b6c5e335b57e5ef6209a689e5d034ec3795c5838bd1707f189
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / dogerpc-0.1.4-py2.py3-none-any.whl

Download URL dogerpc-0.1.4-py2.py3-none-any.whl
Size 15.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bfc66bfa9b98e14cafc756e2642d1c3feea79731fc945b8f72fe74e5acaf0756
BLAKE2b-256 checksum
How to use checksums
dc9d08f852323ceb72c957561a01918be3678e237bb7a813dd0687b55e5245c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for dogerpc 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files No provenance

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