[composite:test] use = call:ts.wsgi.pipeline:factory pipeline = mid1 mid2 app
[filter:mid1] paste.filter_factory = xxx:xxx.factory
[filter:app] paste.filter_factory = xxx:xxx.factory
def factory(loader, global_conf, **local_conf):
"""Service entry method, packaging a series of middleware applications.
:param loader:
:param global_conf:
:param local_conf:
:return:
"""
pipeline = local_conf["pipeline"].split()
app = loader.get_app(pipeline[-1])
filters = [loader.get_filter(filter_name) for filter_name in pipeline[:-1]]
filters.reverse()
for _filter in filters:
app = _filter(app)
return app
class Mid1(base.Middleware):
"""..."""
@webob.dec.wsgify(RequestClass=wsgi.Request)
def __call__(self, req):
headers = req.headers
environ = req.environ
# todo
# 业务逻辑
return req.get_response(self.application)
这里用到了oslo_middleware三方库
class App(object):
"""..."""
@classmethod
def factory(cls, global_config, **local_config):
return cls()
@webob.dec.wsgify(RequestClass=wsgi.Request)
def __call__(self, req):
# todo
# 业务逻辑
return webob.Response(body=resp.content,
status=resp.status_code,
headerlist=resp.headers.items())
def main():
CONF(sys.argv[1:], project="test", prog="test")
logging.setup(CONF, "test")
launcher = service.get_launcher()
server = service.Service("test")
launcher.launch_service(server)
launcher.wait()
这里用到了oslo_service三方库