Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 69 lines (49 sloc) 1.96 KB

Hermodur

Introduction

AMQP/WebSocket handler for Tornado web server. The purpose of Hermodur is to forward messages from an AMQP server to a client connected to the Tornado server via a socket.io server. The main benefits of this are two:

  • Only one connection is opened to the AMQP server (a single instance of RabbitMQ supports rougly 800)
  • Since the listener is a socket.io server it enables older browsers that do not have WebSocket implemented to connect.

Installation

There are two ways to install hermodur onto your system

# old school - setup tools
python setup.py

# new way - using pip
pip install http://github.com/vis-netlausnir/hermodur/tarball/master

How to use

In order to load the HermodurConnection into the Tornado ioloop it has to be configured and the connection the AMQP server has to be initiated. Below is a small example

from tornado import web

from tornadio2 import TornadioRouter, SocketServer
from hermodur import HermodurConnection


class SocketIOHandler(web.RequestHandler):
    def get(self):
        self.render('../socket.io.js')

# We use the defaults localhost:5672 and guest:guest on vhost '/'
HermodurConnection.setup_connection()

# Use the routes classmethod to build the correct resource
HermodurRouter = TornadioRouter(HermodurConnection)

# configure the Tornado application
application = web.Application(
    HermodurRouter.urls,
    socket_io_port = 8001
)

if __name__ == '__main__':
    import logging
    logging.getLogger().setLevel(logging.DEBUG)

    # Create and start tornadio server
    SocketServer(application)

The client then connects using a socket.io client and a connection method supported by the client's browser. When the connection to the server is established the client simply send a JSON message containing the desired exchange and routing_key.

{ "exchange": "my_exchange", "routing_key": "my_routing_key" }

A more detailed example will be added soon ...