ideadevice / zwsgi

ZeroMQ <-> WSGI Bridge (work in progress)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZWSGI

zwsgi provides the power of rich ZeroMQ messaging library to your existing WSGI applications. It changes the underlying transport layer from HTTP to ZHTTP. It is built on top of [pyzmq] (https://github.com/zeromq/pyzmq "pyzmq") bindings and can be configured to use threads, greenlets or processes to handle incoming requests.

Sample Use Case

zwsgi can be used to realize advanced ZeroMQ patterns like [Majordomo Protocol] (http://rfc.zeromq.org/spec:7 "MDP"), where workers are zwsgi applications that connect to a broker. It can be used as a building block to design application architectures based on microservices.

Examples

Sample Flask App (Threads).

from flask import Flask
from zwsgi.servers import ZMQRouterDealerServer as WSGIServer

app = Flask(__name__)

@app.route('/ping')
def hello_world():
    return 'Hello World!'


server = WSGIServer(('127.0.0.1', 7000), app)
server.serve_forever()

Sample Flask App (Gevent).

from flask import Flask
from zwsgi import monkey
monkey.patch_all()
from zwsgi.servers import ZMQRouterDealerServer as WSGIServer


app = Flask(__name__)

@app.route('/ping')
def hello_world():
    return 'Hello World!'


server = WSGIServer(('127.0.0.1', 7000), app)
server.serve_forever()

Sample Flask App (MultiProcess).

from flask import Flask
from multiprocessing import Process
from zwsgi.servers import ZMQRouterDealerServer as WSGIServer

app = Flask(__name__)

@app.route('/ping')
def hello_world():
    return 'Hello World!'

server = WSGIServer(('127.0.0.1', 7000), app, spawn_type=Process)
server.serve_forever()

About

ZeroMQ <-> WSGI Bridge (work in progress)


Languages

Language:Python 100.0%