Data storage and publishing¶
In order to publish data to listeners, Tornadose utilizes a data store concept somewhat reminiscent of that used in Flux. In short, subscribers start listening to a data store and are notified when there are updates.
-
class
tornadose.stores.
BaseStore
(*args, **kwargs)[source]¶ Base class for all data store types.
At a minimum, derived classes should implement
submit
andpublish
methods.-
initialize
(*args, **kwargs)[source]¶ Hook for doing custom initialization. Child classes should implement this method instead of overwriting
__init__
.
-
publish
()[source]¶ Push messages to all listeners. This method must be implemented by child classes. A recommended way to implement this method is as a looping coroutine which yields until new data is available via the
submit()
method.
-
-
class
tornadose.stores.
DataStore
(*args, **kwargs)[source]¶ Generic object for producing data to feed to clients.
To use this, simply instantiate and update the
data
property whenever new data is available. When creating a newEventSource
handler, specify theDataStore
instance so that theEventSource
can listen for updates.
-
class
tornadose.stores.
QueueStore
(*args, **kwargs)[source]¶ Publish data via queues.
This class is meant to be used in cases where subscribers should not miss any data. Compared to the
DataStore
class, new messages to be broadcast to clients are put in a queue to be processed in order.QueueStore
will work with anytornado.web.RequestHandler
subclasses which implement asubmit
method. It is recommended that a custom subscription handler’ssubmit()
method also utilize a queue to avoid losing data. The subscriber must also register/deregister itself with theQueueStore
via theQueueStore.register()
andQueueStore.deregister()
methods.A
QueueStore
-compatible request handler is included intornadose.handlers.WebSocketSubscriber
.