Class RedeliveryErrorHandler
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.ChildServiceSupport
org.apache.camel.processor.errorhandler.ErrorHandlerSupport
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.AsyncProcessor,org.apache.camel.Navigate<org.apache.camel.Processor>,org.apache.camel.Processor,org.apache.camel.Service,org.apache.camel.ShutdownableService,org.apache.camel.spi.ErrorHandler,org.apache.camel.spi.ErrorHandlerRedeliveryCustomizer,org.apache.camel.spi.ShutdownPrepared,org.apache.camel.StatefulService,org.apache.camel.SuspendableService
- Direct Known Subclasses:
DeadLetterChannel,DefaultErrorHandler
public abstract class RedeliveryErrorHandler
extends ErrorHandlerSupport
implements org.apache.camel.spi.ErrorHandlerRedeliveryCustomizer, org.apache.camel.AsyncProcessor, org.apache.camel.spi.ShutdownPrepared, org.apache.camel.Navigate<org.apache.camel.Processor>
Base redeliverable error handler that also supports a final dead letter queue in case all redelivery attempts fail.
This implementation should contain all the error handling logic and the sub classes should only configure it
according to what they support.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classTask to perform calling the processor and handling redelivery if it fails (more advanced than ProcessTask)protected classSimple task to perform calling the processor with no redelivery support -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.camel.spi.AsyncProcessorAwaitManagerprotected final org.apache.camel.CamelContextprotected final booleanprotected final org.apache.camel.Processorprotected final booleanprotected final Stringprotected final org.apache.camel.spi.ExchangeFormatterprotected ScheduledExecutorServiceprotected final org.apache.camel.spi.CamelLoggerprotected final org.apache.camel.Processorprotected final org.apache.camel.Processorprotected org.apache.camel.Processorprotected org.apache.camel.AsyncProcessorprotected booleanprotected final org.apache.camel.spi.ReactiveExecutorprotected booleanprotected final RedeliveryPolicyprotected final org.apache.camel.Processorprotected final AtomicIntegerprotected final org.apache.camel.Predicateprotected final org.apache.camel.spi.ShutdownStrategyprotected booleanprotected PooledExchangeTaskFactoryprotected final booleanprotected final booleanFields inherited from class org.apache.camel.processor.errorhandler.ErrorHandlerSupport
DEFAULT_EXCHANGE_FORMATTER, exceptionPolicies, exceptionPolicyFields inherited from class org.apache.camel.support.ChildServiceSupport
childServicesFields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING -
Constructor Summary
ConstructorsConstructorDescriptionRedeliveryErrorHandler(org.apache.camel.CamelContext camelContext, org.apache.camel.Processor output, org.apache.camel.spi.CamelLogger logger, org.apache.camel.Processor redeliveryProcessor, RedeliveryPolicy redeliveryPolicy, org.apache.camel.Processor deadLetter, String deadLetterUri, boolean deadLetterHandleNewException, boolean useOriginalMessagePolicy, boolean useOriginalBodyPolicy, org.apache.camel.Predicate retryWhile, ScheduledExecutorService executorService, org.apache.camel.Processor onPrepareProcessor, org.apache.camel.Processor onExceptionProcessor) -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeOutput(org.apache.camel.Processor output) protected org.apache.camel.ExchangedefensiveCopyExchangeIfNeeded(org.apache.camel.Exchange exchange) Performs a defensive copy of the exchange if neededbooleanprotected longdetermineRedeliveryDelay(org.apache.camel.Exchange exchange, RedeliveryPolicy redeliveryPolicy, long redeliveryDelay, int redeliveryCounter) Determines the redelivery delay time by first inspecting the Message headerExchange.REDELIVERY_DELAYand if not present, defaulting toRedeliveryPolicy.calculateRedeliveryDelay(long, int)protected voidprotected voiddoStart()org.apache.camel.ProcessorReturns the dead letter that message exchanges will be sent to if the redelivery attempts failprotected org.apache.camel.Predicateorg.apache.camel.spi.CamelLoggerorg.apache.camel.ProcessorGets the outputbooleanhasNext()booleanprotected booleanisDone(org.apache.camel.Exchange exchange) Strategy to determine if the exchange is done so we can continueprotected booleanbooleanbooleanList<org.apache.camel.Processor> next()voidprepareShutdown(boolean suspendOnly, boolean forced) voidprocess(org.apache.camel.Exchange exchange) booleanprocess(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback) Process the exchange using redelivery error handling.CompletableFuture<org.apache.camel.Exchange> processAsync(org.apache.camel.Exchange exchange) booleanWhether this error handler supports transacted exchanges or not.Methods inherited from class org.apache.camel.processor.errorhandler.ErrorHandlerSupport
addErrorHandler, addExceptionPolicy, clone, getExceptionPolicy, isDeadLetterChannelMethods inherited from class org.apache.camel.support.ChildServiceSupport
addChildService, removeChildService, shutdown, start, stopMethods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doInit, doLifecycleChange, doResume, doStop, doSuspend, fail, getInternalLock, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, suspendMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.camel.Service
build, close, initMethods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Field Details
-
taskFactory
-
redeliverySleepCounter
-
executorService
-
preparingShutdown
protected volatile boolean preparingShutdown -
output
protected org.apache.camel.Processor output -
outputAsync
protected org.apache.camel.AsyncProcessor outputAsync -
camelContext
protected final org.apache.camel.CamelContext camelContext -
reactiveExecutor
protected final org.apache.camel.spi.ReactiveExecutor reactiveExecutor -
awaitManager
protected final org.apache.camel.spi.AsyncProcessorAwaitManager awaitManager -
shutdownStrategy
protected final org.apache.camel.spi.ShutdownStrategy shutdownStrategy -
deadLetter
protected final org.apache.camel.Processor deadLetter -
deadLetterUri
-
deadLetterHandleNewException
protected final boolean deadLetterHandleNewException -
redeliveryProcessor
protected final org.apache.camel.Processor redeliveryProcessor -
redeliveryPolicy
-
retryWhilePolicy
protected final org.apache.camel.Predicate retryWhilePolicy -
logger
protected final org.apache.camel.spi.CamelLogger logger -
useOriginalMessagePolicy
protected final boolean useOriginalMessagePolicy -
useOriginalBodyPolicy
protected final boolean useOriginalBodyPolicy -
redeliveryEnabled
protected boolean redeliveryEnabled -
simpleTask
protected boolean simpleTask -
exchangeFormatter
protected final org.apache.camel.spi.ExchangeFormatter exchangeFormatter -
customExchangeFormatter
protected final boolean customExchangeFormatter -
onPrepareProcessor
protected final org.apache.camel.Processor onPrepareProcessor -
onExceptionProcessor
protected final org.apache.camel.Processor onExceptionProcessor
-
-
Constructor Details
-
RedeliveryErrorHandler
public RedeliveryErrorHandler(org.apache.camel.CamelContext camelContext, org.apache.camel.Processor output, org.apache.camel.spi.CamelLogger logger, org.apache.camel.Processor redeliveryProcessor, RedeliveryPolicy redeliveryPolicy, org.apache.camel.Processor deadLetter, String deadLetterUri, boolean deadLetterHandleNewException, boolean useOriginalMessagePolicy, boolean useOriginalBodyPolicy, org.apache.camel.Predicate retryWhile, ScheduledExecutorService executorService, org.apache.camel.Processor onPrepareProcessor, org.apache.camel.Processor onExceptionProcessor)
-
-
Method Details
-
process
public void process(org.apache.camel.Exchange exchange) - Specified by:
processin interfaceorg.apache.camel.Processor
-
process
public boolean process(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback) Process the exchange using redelivery error handling.- Specified by:
processin interfaceorg.apache.camel.AsyncProcessor
-
processAsync
public CompletableFuture<org.apache.camel.Exchange> processAsync(org.apache.camel.Exchange exchange) - Specified by:
processAsyncin interfaceorg.apache.camel.AsyncProcessor
-
changeOutput
public void changeOutput(org.apache.camel.Processor output) - Specified by:
changeOutputin interfaceorg.apache.camel.spi.ErrorHandlerRedeliveryCustomizer
-
supportTransacted
public boolean supportTransacted()Description copied from class:ErrorHandlerSupportWhether this error handler supports transacted exchanges or not.- Specified by:
supportTransactedin classErrorHandlerSupport
-
hasNext
public boolean hasNext()- Specified by:
hasNextin interfaceorg.apache.camel.Navigate<org.apache.camel.Processor>
-
next
- Specified by:
nextin interfaceorg.apache.camel.Navigate<org.apache.camel.Processor>
-
isRunAllowedOnPreparingShutdown
protected boolean isRunAllowedOnPreparingShutdown() -
prepareShutdown
public void prepareShutdown(boolean suspendOnly, boolean forced) - Specified by:
prepareShutdownin interfaceorg.apache.camel.spi.ShutdownPrepared
-
determineRedeliveryDelay
protected long determineRedeliveryDelay(org.apache.camel.Exchange exchange, RedeliveryPolicy redeliveryPolicy, long redeliveryDelay, int redeliveryCounter) Determines the redelivery delay time by first inspecting the Message header
Exchange.REDELIVERY_DELAYand if not present, defaulting toRedeliveryPolicy.calculateRedeliveryDelay(long, int)In order to prevent manipulation of the RedeliveryData state, the values of
RedeliveryErrorHandler.RedeliveryTask.redeliveryDelayandRedeliveryErrorHandler.RedeliveryTask.redeliveryCounterare copied in.- Parameters:
exchange- The current exchange in question.redeliveryPolicy- The RedeliveryPolicy to use in the calculation.redeliveryDelay- The default redelivery delay from RedeliveryDataredeliveryCounter- The redeliveryCounter- Returns:
- The time to wait before the next redelivery.
-
defensiveCopyExchangeIfNeeded
protected org.apache.camel.Exchange defensiveCopyExchangeIfNeeded(org.apache.camel.Exchange exchange) Performs a defensive copy of the exchange if needed- Parameters:
exchange- the exchange- Returns:
- the defensive copy, or null if not needed (redelivery is not enabled).
-
isDone
protected boolean isDone(org.apache.camel.Exchange exchange) Strategy to determine if the exchange is done so we can continue -
getOutput
public org.apache.camel.Processor getOutput()Description copied from class:ErrorHandlerSupportGets the output- Specified by:
getOutputin interfaceorg.apache.camel.spi.ErrorHandlerRedeliveryCustomizer- Specified by:
getOutputin classErrorHandlerSupport
-
getDeadLetter
public org.apache.camel.Processor getDeadLetter()Returns the dead letter that message exchanges will be sent to if the redelivery attempts fail -
getDeadLetterUri
-
isUseOriginalMessagePolicy
public boolean isUseOriginalMessagePolicy() -
isUseOriginalBodyPolicy
public boolean isUseOriginalBodyPolicy() -
isDeadLetterHandleNewException
public boolean isDeadLetterHandleNewException() -
getRedeliveryPolicy
-
getLogger
public org.apache.camel.spi.CamelLogger getLogger() -
getDefaultHandledPredicate
protected org.apache.camel.Predicate getDefaultHandledPredicate() -
determineIfRedeliveryIsEnabled
- Specified by:
determineIfRedeliveryIsEnabledin interfaceorg.apache.camel.spi.ErrorHandlerRedeliveryCustomizer- Throws:
Exception
-
doStart
- Overrides:
doStartin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doShutdown
- Overrides:
doShutdownin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-