Moksha Middleware

Moksha can run as an application serving platform on its own, but also contains a small piece of WSGI middleware that provides your application with a lot of additional functionality as well. This allows you to use Moksha in your existing WSGI application.

It currently provides the following functionality

  • Sets up the feed storage and cache for widgets
  • Handles dispatching moksha applications, which can be any WSGI app or Controller.
  • Handles dispatching to individual widgets, which are simply ToscaWidgets
  • Sets up SQLAlchemy database engines for each application
  • Initializes applications data models
  • Loads all application configuration
  • Sets up the moksha resource connectors
  • Sets up the stomp callback registry

Using the MokshaMiddleware

Using the MokshaMiddleware with an existing WSGI application is quite simple. It will look a bit different with each framework, but here is how it looks in TurboGears2. If you’re using Moksha as a stand-alone platform, this is automatically setup for you.

"""TurboGears middleware initialization"""
from myapp.config.app_cfg import base_config
from myapp.config.environment import load_environment

# make_base_app will wrap the TG2 app with all the middleware it needs.
make_base_app = base_config.setup_tg_wsgi_app(load_environment)

def make_app(global_conf, full_stack=True, **app_conf):
    from moksha.middleware import make_moksha_middleware
    app = make_base_app(global_conf, wrap_app=make_moksha_middleware,
                        full_stack, **app_conf)
    return app

Note

It currently requires to be wrapped in the paste.registry WSGI middleware. TurboGears2 allows us to easily insert middleware directly on top of the raw application, so we then have the ability to use the paste.registry, sessions, and caching.

Moksha’s Full Platform WSGI Stack

Not only can Moksha be inserted into any existing WSGI-compliant application, but on it’s own offers a comprehensive top-to-bottom middleware stack that provides a vast plethora of additional functionality.

Middleware Function Module
Profiling repoze.profile
Resource compression repoze.squeeze
TG2 Middleware
Application routing/dispatching Routes
Session management Beaker
Caching layer Beaker
Widget resource injection ToscaWidgets
Authentication repoze.who
Authorization repoze.what
Transaction management repoze.tm2
Error handling & Debugging WebError
Registry manager Paste
Moksha Middleware
Your application  

Table Of Contents

Previous topic

Caching

Next topic

Hacking with Moksha

This Page