跳转到主要内容

基于ZeroMQ的简单易用的RPC库

项目描述

ezrpc

基于ZeroMQ的简单易用的RPC库。

https://pypip.in/v/ezrpc/badge.png https://pypip.in/d/ezrpc/badge.png

安装

pip install ezrpc

快速入门

步骤1

创建服务器

# server.py
from ezrpc import Server

# By default, the server binds to all available interfaces
s = Server(server_port=5000, client_port=5001)
s.start()

运行以下命令

python server.py

步骤2

创建工作进程

# worker.py
from ezrpc import Registry, ServerWorker
registry = Registry()

@registry.method
def add(a, b):
        return a + b

@registry.method
def multiply(a, b):
        return a * b

# Point the worker to the Server's IP
w = ServerWorker(sys.argv[1], registry, "tcp://127.0.0.1:5000")
w.run()

根据服务器处理能力运行尽可能多的工作进程

python worker.py worker1
python worker.py worker2
python worker.py worker3

工作进程是弹性的,即您可以随意启动和停止它们,客户端将继续提供服务。

步骤3

创建客户端

# client.py
from ezrpc import Client

# Point the client to the Server's IP
# timeout (millis) is optional, default is 5 seconds
c = Client('tcp://127.0.0.1:5001', timeout=1000)

for i in range(1,11):
        res = c.ask('add', i, 1)
        print 'Response: %s' % res

c._disconnect()

运行客户端

python client.py

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分发

ezrpc-0.1.0.tar.gz (4.0 kB 查看哈希值)

上传时间

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面