Request handlers

class tornadose.handlers.BaseHandler(application, request, **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 submit() and publish() methods.

class tornadose.handlers.EventSource(application, request, **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 automatically try to reestablish a lost connection.
  • The publish/subscribe pattern is better suited to some applications than the full duplex model of websockets.
initialize(store, period=None)[source]

If period is given, publishers will sleep for approximately the given time in order to throttle data speeds.

publish(*args, **kwargs)[source]

Pushes data to a listener.

class tornadose.handlers.WebSocketSubscriber(application, request, **kwargs)[source]

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

A Websocket-based subscription handler to be used with tornadose.stores.QueueStore.

open(*args, **kwargs)[source]

Register with the publisher.

publish(*args, **kwargs)[source]

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