Transaction interface
The Transaction interface is the basis of reliability for Flume. All themajor components (ie. Sources, Sinks and Channels) must use aFlume Transaction.
A Transaction is implemented within a Channel implementation. EachSource and Sink that is connected to a Channel must obtain aTransaction object. The Sources use a ChannelProcessorto manage the Transactions, the Sinks manage them explicitly viatheir configured Channel. The operation to stage anEvent (put it into a Channel) or extract an Event (take it out of aChannel) is done inside an active Transaction. For example:
- Channel ch = new MemoryChannel();
- Transaction txn = ch.getTransaction();
- txn.begin();
- try {
- // This try clause includes whatever Channel operations you want to do
- Event eventToStage = EventBuilder.withBody("Hello Flume!",
- Charset.forName("UTF-8"));
- ch.put(eventToStage);
- // Event takenEvent = ch.take();
- // ...
- txn.commit();
- } catch (Throwable t) {
- txn.rollback();
- // Log exception, handle individual exceptions as needed
- // re-throw all Errors
- if (t instanceof Error) {
- throw (Error)t;
- }
- } finally {
- txn.close();
- }
Here we get hold of a Transaction from a Channel. After begin()returns, the Transaction is now active/open and the Event is then putinto the Channel. If the put is successful, then the Transaction iscommitted and closed.