Class RollbackOnFailure

java.lang.Object
org.apache.nifi.processor.util.pattern.RollbackOnFailure

public class RollbackOnFailure extends Object

RollbackOnFailure can be used as a function context for process patterns such as Put to provide a configurable error handling.

RollbackOnFailure can add following characteristics to a processor:

  • When disabled, input FlowFiles caused an error will be routed to 'failure' or 'retry' relationship, based on the type of error.
  • When enabled, input FlowFiles are kept in the input queue. A ProcessException is thrown to rollback the process session.
  • It assumes anything happened during a processors onTrigger can rollback, if this is marked as transactional.
  • If transactional and enabled, even if some FlowFiles are already processed, it rollbacks the session when error occurs.
  • If not transactional and enabled, it only rollbacks the session when error occurs only if there was no progress.
  • There are two approaches to apply RollbackOnFailure. One is using ExceptionHandler.adjustError(BiFunction), and the other is implementing processor onTrigger using process patterns such as Put.adjustRoute(AdjustRoute).

    It's also possible to use both approaches. ExceptionHandler can apply when an Exception is thrown immediately, while AdjustRoute respond later but requires less code.

    • Field Details

      • rollbackOnFailure

        private final boolean rollbackOnFailure
      • transactional

        private final boolean transactional
      • discontinue

        private boolean discontinue
      • processedCount

        private int processedCount
      • ROLLBACK_ON_FAILURE

        public static final org.apache.nifi.components.PropertyDescriptor ROLLBACK_ON_FAILURE
    • Constructor Details

      • RollbackOnFailure

        public RollbackOnFailure(boolean rollbackOnFailure, boolean transactional)
        Constructor.
        Parameters:
        rollbackOnFailure - Should be set by user via processor configuration.
        transactional - Specify whether a processor is transactional. If not, it is important to call proceed() after successful execution of processors task, that indicates processor made an operation that can not be undone.
    • Method Details

      • createRollbackOnFailureProperty

        public static org.apache.nifi.components.PropertyDescriptor createRollbackOnFailureProperty(String additionalDescription)
      • createAdjustError

        public static <FCT extends RollbackOnFailure> BiFunction<FCT,ErrorTypes,ErrorTypes.Result> createAdjustError(org.apache.nifi.logging.ComponentLog logger)
        Create a function to use with ExceptionHandler that adjust error type based on functional context.
      • createAdjustRoute

        public static <FCT extends RollbackOnFailure> PartialFunctions.AdjustRoute<FCT> createAdjustRoute(org.apache.nifi.processor.Relationship... failureRelationships)
        Create an PartialFunctions.AdjustRoute function to use with process pattern such as Put that adjust routed FlowFiles based on context. This function works as a safety net by covering cases that Processor implementation did not use ExceptionHandler and transfer FlowFiles without considering RollbackOnFailure context.
      • createOnError

        public static <FCT extends RollbackOnFailure, I> ExceptionHandler.OnError<FCT,I> createOnError(ExceptionHandler.OnError<FCT,I> onError)
      • onTrigger

        public static <FCT extends RollbackOnFailure> void onTrigger(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSessionFactory sessionFactory, FCT functionContext, org.apache.nifi.logging.ComponentLog logger, PartialFunctions.OnTrigger onTrigger) throws org.apache.nifi.processor.exception.ProcessException
        Throws:
        org.apache.nifi.processor.exception.ProcessException
      • proceed

        public int proceed()
      • getProcessedCount

        public int getProcessedCount()
      • isRollbackOnFailure

        public boolean isRollbackOnFailure()
      • isTransactional

        public boolean isTransactional()
      • canRollback

        public boolean canRollback()
      • shouldDiscontinue

        public boolean shouldDiscontinue()
      • discontinue

        public void discontinue()