Data storage and publishing¶
In order to publish data to listeners, Tornadose utilizes a data store concept in which subscribers listen to a data store to receive 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.
-
class
tornadose.stores.
RedisStore
(*args, **kwargs)[source]¶ Publish data via a Redis backend.
This data store works in a similar manner as
DataStore
. The primary advantage is that external programs can be used to publish data to be consumed by clients.The
channel
keyword argument specifies which Redis channel to publish to and defaults totornadose
.All remaining keyword arguments are passed directly to the
redis.StrictRedis
constructor. See redis-py‘s documentation for detais.New messages are read in a background thread via a
concurrent.futures.ThreadPoolExecutor
. This requires either Python >= 3.2 or the backportedfutures
module to be installed.Raises: ConnectionError – when the Redis host is not pingable