Class RedeliveryPolicy
java.lang.Object
org.apache.camel.processor.errorhandler.RedeliveryPolicy
- All Implemented Interfaces:
Serializable
,Cloneable
The policy used to decide how many times to redeliver and the time between the redeliveries before being sent to a
Dead Letter Channel
The delay pattern syntax is: limit:delay;limit 2:delay 2;limit 3:delay 3;...;limit N:delay N. How it works is best illustrate with an example with this pattern: delayPattern=5:1000;10:5000:20:20000
The delays will be for attempt in range 0..4 = 0 millis, 5..9 = 1000 millis, 10..19 = 5000 millis, >= 20 = 20000 millis. If you want to set a starting delay, then use 0 as the first limit, eg: 0:1000;5:5000 will use 1 sec delay until attempt number 5 where it will use 5 seconds going forward.
The default values are:
- maximumRedeliveries = 0
- redeliveryDelay = 1000L (the initial delay)
- maximumRedeliveryDelay = 60 * 1000L
- asyncDelayedRedelivery = false
- backOffMultiplier = 2
- useExponentialBackOff = false
- collisionAvoidanceFactor = 0.15d
- useCollisionAvoidance = false
- retriesExhaustedLogLevel = LoggingLevel.ERROR
- retryAttemptedLogLevel = LoggingLevel.DEBUG
- retryAttemptedLogInterval = 1
- logRetryAttempted = true
- logRetryStackTrace = false
- logStackTrace = true
- logHandled = false
- logExhausted = true
- logExhaustedMessageHistory = true
- logExhaustedMessageBody = false
- logNewException = true
- allowRedeliveryWhileStopping = true
- using conventional options, using all the options defined above
- using delay pattern to declare intervals for delays
The delay pattern syntax is: limit:delay;limit 2:delay 2;limit 3:delay 3;...;limit N:delay N. How it works is best illustrate with an example with this pattern: delayPattern=5:1000;10:5000:20:20000
The delays will be for attempt in range 0..4 = 0 millis, 5..9 = 1000 millis, 10..19 = 5000 millis, >= 20 = 20000 millis. If you want to set a starting delay, then use 0 as the first limit, eg: 0:1000;5:5000 will use 1 sec delay until attempt number 5 where it will use 5 seconds going forward.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected boolean
protected double
protected double
static final RedeliveryPolicy
protected String
protected String
protected boolean
protected boolean
protected Boolean
protected Boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected int
protected long
protected static Random
protected long
protected org.apache.camel.LoggingLevel
protected int
protected org.apache.camel.LoggingLevel
protected boolean
protected boolean
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionallowRedeliveryWhileStopping
(boolean redeliverWhileStopping) Controls whether to allow redelivery while stopping/shutting down a route that uses error handling.Allow asynchronous delayed redelivery.backOffMultiplier
(double multiplier) Enables exponential backoff and sets the multiplier used to increase the delay between redeliveriesprotected static long
calculateRedeliverDelayUsingPattern
(String delayPattern, int redeliveryCounter) Calculates the delay using the delay patternlong
calculateRedeliveryDelay
(long previousDelay, int redeliveryCounter) Calculates the new redelivery delay based on the last onecollisionAvoidancePercent
(double collisionAvoidancePercent) Enables collision avoidance and sets the percentage usedcopy()
delayPattern
(String delayPattern) Sets the delay pattern with delay intervals.Disables redelivery by setting maximum redeliveries to 0.exchangeFormatterRef
(String exchangeFormatterRef) Sets the reference of the instance ofExchangeFormatter
to generate the log message from exchange.double
double
long
Whether the option logExhaustedMessageBody has been configured or notWhether the option logExhaustedMessageHistory has been configured or notint
long
protected static Random
long
org.apache.camel.LoggingLevel
int
org.apache.camel.LoggingLevel
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
logExhausted
(boolean logExhausted) Sets whether to log exhausted errorslogExhaustedMessageBody
(boolean logExhaustedMessageBody) Sets whether to log exhausted errors including message body (requires message history to be enabled)logExhaustedMessageHistory
(boolean logExhaustedMessageHistory) Sets whether to log exhausted errors including message historylogHandled
(boolean logHandled) Sets whether to log errors even if its handledlogNewException
(boolean logNewException) Sets whether errors should be logged when a new exception occurred during handling a previous exceptionlogRetryAttempted
(boolean logRetryAttempted) Sets whether to log retry attemptslogRetryStackTrace
(boolean logRetryStackTrace) Sets whether to log stacktrace for failed redelivery attemptslogStackTrace
(boolean logStackTrace) Sets whether to log stacktrace for failed messages.maximumRedeliveries
(int maximumRedeliveries) Sets the maximum number of times a message exchange will be redeliveredmaximumRedeliveryDelay
(long maximumRedeliveryDelay) Sets the maximum redelivery delay if using exponential back off.redeliveryDelay
(long delay) Sets the initial redelivery delay in millisecondsretriesExhaustedLogLevel
(org.apache.camel.LoggingLevel retriesExhaustedLogLevel) Sets the logging level to use for log messages when retries have been exhausted.retryAttemptedLogInterval
(int logRetryAttemptedInterval) Sets the interval to log retry attemptsretryAttemptedLogLevel
(org.apache.camel.LoggingLevel retryAttemptedLogLevel) Sets the logging level to use for log messages when retries are attempted.void
setAllowRedeliveryWhileStopping
(boolean allowRedeliveryWhileStopping) Controls whether to allow redelivery while stopping/shutting down a route that uses error handling.void
setAsyncDelayedRedelivery
(boolean asyncDelayedRedelivery) Sets whether asynchronous delayed redelivery is allowed.void
setBackOffMultiplier
(double backOffMultiplier) Sets the multiplier used to increase the delay between redeliveries ifsetUseExponentialBackOff(boolean)
is enabledvoid
setCollisionAvoidanceFactor
(double collisionAvoidanceFactor) Sets the factor used for collision avoidance if enabled viasetUseCollisionAvoidance(boolean)
void
setCollisionAvoidancePercent
(double collisionAvoidancePercent) Sets the percentage used for collision avoidance if enabled viasetUseCollisionAvoidance(boolean)
void
setDelayPattern
(String delayPattern) Sets an optional delay pattern to use instead of fixed delay.void
setExchangeFormatterRef
(String exchangeFormatterRef) Sets the reference of the instance ofExchangeFormatter
to generate the log message from exchange.void
setLogContinued
(boolean logContinued) Sets whether errors should be logged even if its continuedvoid
setLogExhausted
(boolean logExhausted) Sets whether exhausted exceptions should be logged or notvoid
setLogExhaustedMessageBody
(Boolean logExhaustedMessageBody) Sets whether exhausted message body/headers should be logged with message history included (requires logExhaustedMessageHistory to be enabled).void
setLogExhaustedMessageHistory
(boolean logExhaustedMessageHistory) Sets whether exhausted exceptions should be logged with message history included.void
setLogHandled
(boolean logHandled) Sets whether errors should be logged even if its handledvoid
setLogNewException
(boolean logNewException) Sets whether errors should be logged when a new exception occurred during handling a previous exceptionvoid
setLogRetryAttempted
(boolean logRetryAttempted) Sets whether retry attempts should be logged or notvoid
setLogRetryStackTrace
(boolean logRetryStackTrace) Sets whether stack traces should be logged or notvoid
setLogStackTrace
(boolean logStackTrace) Sets whether stack traces should be logged or notvoid
setMaximumRedeliveries
(int maximumRedeliveries) Sets the maximum number of times a message exchange will be redelivered.void
setMaximumRedeliveryDelay
(long maximumRedeliveryDelay) Sets the maximum redelivery delay.void
setRedeliveryDelay
(long redeliverDelay) Sets the initial redelivery delay in millisecondsvoid
setRetriesExhaustedLogLevel
(org.apache.camel.LoggingLevel retriesExhaustedLogLevel) Sets the logging level to use for log messages when retries have been exhausted.void
setRetryAttemptedLogInterval
(int retryAttemptedLogInterval) Sets the interval to log retry attemptsvoid
setRetryAttemptedLogLevel
(org.apache.camel.LoggingLevel retryAttemptedLogLevel) Sets the logging level to use for log messages when retries are attempted.void
setUseCollisionAvoidance
(boolean useCollisionAvoidance) Enables/disables collision avoidance which adds some randomization to the backoff timings to reduce contention probabilityvoid
setUseExponentialBackOff
(boolean useExponentialBackOff) Enables/disables exponential backoff using thegetBackOffMultiplier()
to increase the time between retriesboolean
shouldRedeliver
(org.apache.camel.Exchange exchange, int redeliveryCounter, org.apache.camel.Predicate retryWhile) Returns true if the policy decides that the message exchange should be redelivered.void
sleep
(long redeliveryDelay) Sleeps for the given delaylong
sleep
(long redeliveryDelay, int redeliveryCounter) Calculates the new redelivery delay based on the last one and then sleeps for the necessary amount of time.toString()
Enables collision avoidance which adds some randomization to the backoff timings to reduce contention probabilityEnables exponential backoff using thegetBackOffMultiplier()
to increase the time between retries
-
Field Details
-
DEFAULT_POLICY
-
randomNumberGenerator
-
redeliveryDelay
protected long redeliveryDelay -
maximumRedeliveries
protected int maximumRedeliveries -
maximumRedeliveryDelay
protected long maximumRedeliveryDelay -
backOffMultiplier
protected double backOffMultiplier -
useExponentialBackOff
protected boolean useExponentialBackOff -
collisionAvoidanceFactor
protected double collisionAvoidanceFactor -
useCollisionAvoidance
protected boolean useCollisionAvoidance -
retriesExhaustedLogLevel
protected org.apache.camel.LoggingLevel retriesExhaustedLogLevel -
retryAttemptedLogLevel
protected org.apache.camel.LoggingLevel retryAttemptedLogLevel -
retryAttemptedLogInterval
protected int retryAttemptedLogInterval -
logStackTrace
protected boolean logStackTrace -
logRetryStackTrace
protected boolean logRetryStackTrace -
logHandled
protected boolean logHandled -
logContinued
protected boolean logContinued -
logExhausted
protected boolean logExhausted -
logNewException
protected boolean logNewException -
logExhaustedMessageHistory
-
logExhaustedMessageBody
-
logRetryAttempted
protected boolean logRetryAttempted -
delayPattern
-
asyncDelayedRedelivery
protected boolean asyncDelayedRedelivery -
allowRedeliveryWhileStopping
protected boolean allowRedeliveryWhileStopping -
exchangeFormatterRef
-
-
Constructor Details
-
RedeliveryPolicy
public RedeliveryPolicy()
-
-
Method Details
-
toString
-
copy
-
shouldRedeliver
public boolean shouldRedeliver(org.apache.camel.Exchange exchange, int redeliveryCounter, org.apache.camel.Predicate retryWhile) Returns true if the policy decides that the message exchange should be redelivered.- Parameters:
exchange
- the current exchangeredeliveryCounter
- the current retry counterretryWhile
- an optional predicate to determine if we should redeliver or not- Returns:
- true to redeliver, false to stop
-
sleep
Calculates the new redelivery delay based on the last one and then sleeps for the necessary amount of time. This implementation will block while sleeping.- Parameters:
redeliveryDelay
- previous redelivery delayredeliveryCounter
- number of previous redelivery attempts- Returns:
- the calculate delay
- Throws:
InterruptedException
- is thrown if the sleep is interrupted likely because of shutdown
-
sleep
Sleeps for the given delay- Parameters:
redeliveryDelay
- the delay- Throws:
InterruptedException
- is thrown if the sleep is interrupted likely because of shutdown
-
calculateRedeliveryDelay
public long calculateRedeliveryDelay(long previousDelay, int redeliveryCounter) Calculates the new redelivery delay based on the last one- Parameters:
previousDelay
- previous redelivery delayredeliveryCounter
- number of previous redelivery attempts- Returns:
- the calculate delay
-
calculateRedeliverDelayUsingPattern
protected static long calculateRedeliverDelayUsingPattern(String delayPattern, int redeliveryCounter) Calculates the delay using the delay pattern -
redeliveryDelay
Sets the initial redelivery delay in milliseconds -
maximumRedeliveries
Sets the maximum number of times a message exchange will be redelivered -
useCollisionAvoidance
Enables collision avoidance which adds some randomization to the backoff timings to reduce contention probability -
useExponentialBackOff
Enables exponential backoff using thegetBackOffMultiplier()
to increase the time between retries -
backOffMultiplier
Enables exponential backoff and sets the multiplier used to increase the delay between redeliveries -
collisionAvoidancePercent
Enables collision avoidance and sets the percentage used -
maximumRedeliveryDelay
Sets the maximum redelivery delay if using exponential back off. Use -1 if you wish to have no maximum -
retriesExhaustedLogLevel
public RedeliveryPolicy retriesExhaustedLogLevel(org.apache.camel.LoggingLevel retriesExhaustedLogLevel) Sets the logging level to use for log messages when retries have been exhausted. -
retryAttemptedLogLevel
public RedeliveryPolicy retryAttemptedLogLevel(org.apache.camel.LoggingLevel retryAttemptedLogLevel) Sets the logging level to use for log messages when retries are attempted. -
retryAttemptedLogInterval
Sets the interval to log retry attempts -
logRetryAttempted
Sets whether to log retry attempts -
logStackTrace
Sets whether to log stacktrace for failed messages. -
logRetryStackTrace
Sets whether to log stacktrace for failed redelivery attempts -
logHandled
Sets whether to log errors even if its handled -
logNewException
Sets whether errors should be logged when a new exception occurred during handling a previous exception -
logExhausted
Sets whether to log exhausted errors -
logExhaustedMessageHistory
Sets whether to log exhausted errors including message history -
logExhaustedMessageBody
Sets whether to log exhausted errors including message body (requires message history to be enabled) -
delayPattern
Sets the delay pattern with delay intervals. -
disableRedelivery
Disables redelivery by setting maximum redeliveries to 0. -
asyncDelayedRedelivery
Allow asynchronous delayed redelivery.- See Also:
-
allowRedeliveryWhileStopping
Controls whether to allow redelivery while stopping/shutting down a route that uses error handling.- Parameters:
redeliverWhileStopping
- true to allow redelivery, false to reject redeliveries
-
exchangeFormatterRef
Sets the reference of the instance ofExchangeFormatter
to generate the log message from exchange.- Parameters:
exchangeFormatterRef
- name of the instance ofExchangeFormatter
- Returns:
- the builder
-
getRedeliveryDelay
public long getRedeliveryDelay() -
setRedeliveryDelay
public void setRedeliveryDelay(long redeliverDelay) Sets the initial redelivery delay in milliseconds -
getBackOffMultiplier
public double getBackOffMultiplier() -
setBackOffMultiplier
public void setBackOffMultiplier(double backOffMultiplier) Sets the multiplier used to increase the delay between redeliveries ifsetUseExponentialBackOff(boolean)
is enabled -
getCollisionAvoidancePercent
public long getCollisionAvoidancePercent() -
setCollisionAvoidancePercent
public void setCollisionAvoidancePercent(double collisionAvoidancePercent) Sets the percentage used for collision avoidance if enabled viasetUseCollisionAvoidance(boolean)
-
getCollisionAvoidanceFactor
public double getCollisionAvoidanceFactor() -
setCollisionAvoidanceFactor
public void setCollisionAvoidanceFactor(double collisionAvoidanceFactor) Sets the factor used for collision avoidance if enabled viasetUseCollisionAvoidance(boolean)
-
getMaximumRedeliveries
public int getMaximumRedeliveries() -
setMaximumRedeliveries
public void setMaximumRedeliveries(int maximumRedeliveries) Sets the maximum number of times a message exchange will be redelivered. Setting a negative value will retry forever. -
getMaximumRedeliveryDelay
public long getMaximumRedeliveryDelay() -
setMaximumRedeliveryDelay
public void setMaximumRedeliveryDelay(long maximumRedeliveryDelay) Sets the maximum redelivery delay. Use -1 if you wish to have no maximum -
isUseCollisionAvoidance
public boolean isUseCollisionAvoidance() -
setUseCollisionAvoidance
public void setUseCollisionAvoidance(boolean useCollisionAvoidance) Enables/disables collision avoidance which adds some randomization to the backoff timings to reduce contention probability -
isUseExponentialBackOff
public boolean isUseExponentialBackOff() -
setUseExponentialBackOff
public void setUseExponentialBackOff(boolean useExponentialBackOff) Enables/disables exponential backoff using thegetBackOffMultiplier()
to increase the time between retries -
getRandomNumberGenerator
-
setRetriesExhaustedLogLevel
public void setRetriesExhaustedLogLevel(org.apache.camel.LoggingLevel retriesExhaustedLogLevel) Sets the logging level to use for log messages when retries have been exhausted. -
getRetriesExhaustedLogLevel
public org.apache.camel.LoggingLevel getRetriesExhaustedLogLevel() -
setRetryAttemptedLogLevel
public void setRetryAttemptedLogLevel(org.apache.camel.LoggingLevel retryAttemptedLogLevel) Sets the logging level to use for log messages when retries are attempted. -
getRetryAttemptedLogLevel
public org.apache.camel.LoggingLevel getRetryAttemptedLogLevel() -
getRetryAttemptedLogInterval
public int getRetryAttemptedLogInterval() -
setRetryAttemptedLogInterval
public void setRetryAttemptedLogInterval(int retryAttemptedLogInterval) Sets the interval to log retry attempts -
getDelayPattern
-
setDelayPattern
Sets an optional delay pattern to use instead of fixed delay. -
isLogStackTrace
public boolean isLogStackTrace() -
setLogStackTrace
public void setLogStackTrace(boolean logStackTrace) Sets whether stack traces should be logged or not -
isLogRetryStackTrace
public boolean isLogRetryStackTrace() -
setLogRetryStackTrace
public void setLogRetryStackTrace(boolean logRetryStackTrace) Sets whether stack traces should be logged or not -
isLogHandled
public boolean isLogHandled() -
setLogHandled
public void setLogHandled(boolean logHandled) Sets whether errors should be logged even if its handled -
isLogNewException
public boolean isLogNewException() -
setLogNewException
public void setLogNewException(boolean logNewException) Sets whether errors should be logged when a new exception occurred during handling a previous exception -
isLogContinued
public boolean isLogContinued() -
setLogContinued
public void setLogContinued(boolean logContinued) Sets whether errors should be logged even if its continued -
isLogRetryAttempted
public boolean isLogRetryAttempted() -
setLogRetryAttempted
public void setLogRetryAttempted(boolean logRetryAttempted) Sets whether retry attempts should be logged or not -
isLogExhausted
public boolean isLogExhausted() -
setLogExhausted
public void setLogExhausted(boolean logExhausted) Sets whether exhausted exceptions should be logged or not -
isLogExhaustedMessageHistory
public boolean isLogExhaustedMessageHistory() -
getLogExhaustedMessageHistory
Whether the option logExhaustedMessageHistory has been configured or not- Returns:
- null if not configured, or the configured value as true or false
- See Also:
-
setLogExhaustedMessageHistory
public void setLogExhaustedMessageHistory(boolean logExhaustedMessageHistory) Sets whether exhausted exceptions should be logged with message history included. -
isLogExhaustedMessageBody
public boolean isLogExhaustedMessageBody() -
getLogExhaustedMessageBody
Whether the option logExhaustedMessageBody has been configured or not- Returns:
- null if not configured, or the configured value as true or false
- See Also:
-
setLogExhaustedMessageBody
Sets whether exhausted message body/headers should be logged with message history included (requires logExhaustedMessageHistory to be enabled). -
isAsyncDelayedRedelivery
public boolean isAsyncDelayedRedelivery() -
setAsyncDelayedRedelivery
public void setAsyncDelayedRedelivery(boolean asyncDelayedRedelivery) Sets whether asynchronous delayed redelivery is allowed. This is disabled by default. When enabled it allows Camel to schedule a future task for delayed redelivery which prevents current thread from blocking while waiting. Exchange which is transacted will however always use synchronous delayed redelivery because the transaction must execute in the same thread context.- Parameters:
asyncDelayedRedelivery
- whether asynchronous delayed redelivery is allowed
-
isAllowRedeliveryWhileStopping
public boolean isAllowRedeliveryWhileStopping() -
setAllowRedeliveryWhileStopping
public void setAllowRedeliveryWhileStopping(boolean allowRedeliveryWhileStopping) Controls whether to allow redelivery while stopping/shutting down a route that uses error handling.- Parameters:
allowRedeliveryWhileStopping
- true to allow redelivery, false to reject redeliveries
-
getExchangeFormatterRef
-
setExchangeFormatterRef
Sets the reference of the instance ofExchangeFormatter
to generate the log message from exchange.
-