- New sink class
- Backend convenience classes
- Naming and placing the new sink
cygnus-twitter allows for twitter context data persistence in certain storages by means of Flume sinks. As long as the current collection of sinks could be limited for your purposes, you can add your own sinks regarding a persistence technology of your choice and become an official
This document tries to guide you on the development of such alternative sinks, by giving you guidelines about how to write the sink code, but also how the different classes must be called, the backends that can be used, etc.
TwitterSink is the base class all the sinks within
cygnus-twitter extend. It is an abstract class which extends from
CygnusSink class at
cygnus-common (which, by its side, extends Flume's native
TwitterSink provides most of the logic required by any Twitter-like sink:
- Configuration of parameters common to all the sinks.
- Starting and stoping the sink.
- Flume events consumption in a batch-like approach, including opening, committing and closing of Flume transactions.
- Counters for statistics (in fact, this feature is given by
You find this class at the following path:
All the sinks extending
TwitterSink inherit the following configuration parameters:
|batch_size||no||1||Number of events accumulated before persistence.|
|batch_timeout||no||30||Number of seconds the batch will be building before it is persisted as it is.|
|batch_ttl||no||10||Number of retries when a batch cannot be persisted. Use
|enable_lowercase||no||false||Accepted values: true or false.|
These parameters are read (and defaulted, when required) in the
The most important part of
TwitterSink is where the events are consumed in a batch-like approach. This is done in the
process() method inherited from
AbstractSink, which is overwritten.
Such events processing is done by opening a Flume transaction and reading events as specified in the
batch_size parameter (if no enough events are available, the accumulation ends when the
batch_timeout is reached). For each event read, the transaction is committed. Once the accumulations ends the transaction is closed.
Please notice that the
process() method handles all the possible errors that may occur during a Flume transaction by catching exceptions. There exists a collection of Cygnus-related exceptions whose usage is mandatory located at
Specific persistence logic is implemented by overwritting the only abstract method within
abstract void persistBatch(TwitterBatch) throws Exception;
CygnusSink the following counters are already available for retrieving statistics of any sink extending
- Number of processed events, i.e. the number of events taken from the channel and accumulated in a batch for persistence.
- Number of persisted events, i.e. the number of events within batches finally written/inserted/added in the final storage.
configure(Context) method of
TwitterSink can be extended with specific configuration parameters reading (and defaulting, when required).
To store tweets in HDFS, we have added the properties
hdfs_files in the configuration file
agent_<id>.conf to specify the place of storage. For other types of sinks, the required properties should be added in the configuration file and the code of the sink should treat this information in an appropriate way.
Sometimes all the necessary logic to persist the notified context data cannot be coded in the
persist abstract method. In this case, you may want to create a backend class or set of classes wrapping the detailed interactions with the final backend. Nevertheless, these classes should not be located at
cygnus-twitter but at
New sink classes must be called
Twitter<technology>Sink, being technology the name of the persistence backend. An example is the already existent sink
Regarding the new sink class location, it must be:
As already explained, backends must be located at: