Request handlers

Tornadose defines handlers for using the EventSource interface or WebSockets. For other handlers, the BaseHandler class is provided.

class tornadose.handlers.BaseHandler(application: tornado.web.Application, request: tornado.httputil.HTTPServerRequest, **kwargs)[source]

Bases: tornado.web.RequestHandler

Base handler for subscribers. To be compatible with data stores defined in tornadose.stores, custom handlers should inherit this class and implement the publish() method.

initialize(store)[source]

Common initialization of handlers happens here. If additional initialization is required, this method must either be called with super or the child class must assign the store attribute and register itself with the store.

publish()[source]

Push a message to the subscriber. This method must be implemented by child classes.

submit(message)[source]

Submit a new message to be published.

class tornadose.handlers.EventSource(application: tornado.web.Application, request: tornado.httputil.HTTPServerRequest, **kwargs)[source]

Bases: tornadose.handlers.BaseHandler

Handler for server-sent events a.k.a. EventSource.

The EventSource interface has a few advantages over websockets:

  • It is a normal HTTP connection and so can be more easily monitored than websockets using tools like curl or HTTPie.
  • Browsers generally try to reestablish a lost connection automatically.
  • The publish/subscribe pattern is better suited to some applications than the full duplex model of websockets.
initialize(store)[source]

Common initialization of handlers happens here. If additional initialization is required, this method must either be called with super or the child class must assign the store attribute and register itself with the store.

publish(message)[source]

Pushes data to a listener.

class tornadose.handlers.WebSocketSubscriber(application: tornado.web.Application, request: tornado.httputil.HTTPServerRequest, **kwargs)[source]

Bases: tornadose.handlers.BaseHandler, tornado.websocket.WebSocketHandler

A Websocket-based subscription handler.

open()[source]

Register with the publisher.

publish(message)[source]

Push a new message to the client. The data will be available as a JSON object with the key data.