Class RedeliveryPolicy
- java.lang.Object
-
- org.apache.camel.processor.errorhandler.RedeliveryPolicy
-
- All Implemented Interfaces:
Serializable
,Cloneable
@Configurer public class RedeliveryPolicy extends Object implements Cloneable, Serializable
The policy used to decide how many times to redeliver and the time between the redeliveries before being sent to a Dead Letter ChannelThe 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:
- Serialized Form
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description RedeliveryPolicy()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RedeliveryPolicy
allowRedeliveryWhileStopping(boolean redeliverWhileStopping)
Controls whether to allow redelivery while stopping/shutting down a route that uses error handling.RedeliveryPolicy
asyncDelayedRedelivery()
Allow asynchronous delayed redelivery.RedeliveryPolicy
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 oneRedeliveryPolicy
collisionAvoidancePercent(double collisionAvoidancePercent)
Enables collision avoidance and sets the percentage usedRedeliveryPolicy
copy()
RedeliveryPolicy
delayPattern(String delayPattern)
Sets the delay pattern with delay intervals.RedeliveryPolicy
disableRedelivery()
Disables redelivery by setting maximum redeliveries to 0.RedeliveryPolicy
exchangeFormatterRef(String exchangeFormatterRef)
Sets the reference of the instance ofExchangeFormatter
to generate the log message from exchange.double
getBackOffMultiplier()
double
getCollisionAvoidanceFactor()
long
getCollisionAvoidancePercent()
String
getDelayPattern()
String
getExchangeFormatterRef()
Boolean
getLogExhaustedMessageBody()
Whether the option logExhaustedMessageBody has been configured or notBoolean
getLogExhaustedMessageHistory()
Whether the option logExhaustedMessageHistory has been configured or notint
getMaximumRedeliveries()
long
getMaximumRedeliveryDelay()
protected static Random
getRandomNumberGenerator()
long
getRedeliveryDelay()
org.apache.camel.LoggingLevel
getRetriesExhaustedLogLevel()
int
getRetryAttemptedLogInterval()
org.apache.camel.LoggingLevel
getRetryAttemptedLogLevel()
boolean
isAllowRedeliveryWhileStopping()
boolean
isAsyncDelayedRedelivery()
boolean
isLogContinued()
boolean
isLogExhausted()
boolean
isLogExhaustedMessageBody()
boolean
isLogExhaustedMessageHistory()
boolean
isLogHandled()
boolean
isLogNewException()
boolean
isLogRetryAttempted()
boolean
isLogRetryStackTrace()
boolean
isLogStackTrace()
boolean
isUseCollisionAvoidance()
boolean
isUseExponentialBackOff()
RedeliveryPolicy
logExhausted(boolean logExhausted)
Sets whether to log exhausted errorsRedeliveryPolicy
logExhaustedMessageBody(boolean logExhaustedMessageBody)
Sets whether to log exhausted errors including message body (requires message history to be enabled)RedeliveryPolicy
logExhaustedMessageHistory(boolean logExhaustedMessageHistory)
Sets whether to log exhausted errors including message historyRedeliveryPolicy
logHandled(boolean logHandled)
Sets whether to log errors even if its handledRedeliveryPolicy
logNewException(boolean logNewException)
Sets whether errors should be logged when a new exception occurred during handling a previous exceptionRedeliveryPolicy
logRetryAttempted(boolean logRetryAttempted)
Sets whether to log retry attemptsRedeliveryPolicy
logRetryStackTrace(boolean logRetryStackTrace)
Sets whether to log stacktrace for failed redelivery attemptsRedeliveryPolicy
logStackTrace(boolean logStackTrace)
Sets whether to log stacktrace for failed messages.RedeliveryPolicy
maximumRedeliveries(int maximumRedeliveries)
Sets the maximum number of times a message exchange will be redeliveredRedeliveryPolicy
maximumRedeliveryDelay(long maximumRedeliveryDelay)
Sets the maximum redelivery delay if using exponential back off.RedeliveryPolicy
redeliveryDelay(long delay)
Sets the initial redelivery delay in millisecondsRedeliveryPolicy
retriesExhaustedLogLevel(org.apache.camel.LoggingLevel retriesExhaustedLogLevel)
Sets the logging level to use for log messages when retries have been exhausted.RedeliveryPolicy
retryAttemptedLogInterval(int logRetryAttemptedInterval)
Sets the interval to log retry attemptsRedeliveryPolicy
retryAttemptedLogLevel(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.String
toString()
RedeliveryPolicy
useCollisionAvoidance()
Enables collision avoidance which adds some randomization to the backoff timings to reduce contention probabilityRedeliveryPolicy
useExponentialBackOff()
Enables exponential backoff using thegetBackOffMultiplier()
to increase the time between retries
-
-
-
Field Detail
-
DEFAULT_POLICY
public static final RedeliveryPolicy DEFAULT_POLICY
-
randomNumberGenerator
protected static Random 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
protected Boolean logExhaustedMessageHistory
-
logExhaustedMessageBody
protected Boolean logExhaustedMessageBody
-
logRetryAttempted
protected boolean logRetryAttempted
-
delayPattern
protected String delayPattern
-
asyncDelayedRedelivery
protected boolean asyncDelayedRedelivery
-
allowRedeliveryWhileStopping
protected boolean allowRedeliveryWhileStopping
-
exchangeFormatterRef
protected String exchangeFormatterRef
-
-
Method Detail
-
copy
public RedeliveryPolicy 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
public long sleep(long redeliveryDelay, int redeliveryCounter) throws InterruptedException
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
public void sleep(long redeliveryDelay) throws InterruptedException
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
public RedeliveryPolicy redeliveryDelay(long delay)
Sets the initial redelivery delay in milliseconds
-
maximumRedeliveries
public RedeliveryPolicy maximumRedeliveries(int maximumRedeliveries)
Sets the maximum number of times a message exchange will be redelivered
-
useCollisionAvoidance
public RedeliveryPolicy useCollisionAvoidance()
Enables collision avoidance which adds some randomization to the backoff timings to reduce contention probability
-
useExponentialBackOff
public RedeliveryPolicy useExponentialBackOff()
Enables exponential backoff using thegetBackOffMultiplier()
to increase the time between retries
-
backOffMultiplier
public RedeliveryPolicy backOffMultiplier(double multiplier)
Enables exponential backoff and sets the multiplier used to increase the delay between redeliveries
-
collisionAvoidancePercent
public RedeliveryPolicy collisionAvoidancePercent(double collisionAvoidancePercent)
Enables collision avoidance and sets the percentage used
-
maximumRedeliveryDelay
public RedeliveryPolicy maximumRedeliveryDelay(long 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
public RedeliveryPolicy retryAttemptedLogInterval(int logRetryAttemptedInterval)
Sets the interval to log retry attempts
-
logRetryAttempted
public RedeliveryPolicy logRetryAttempted(boolean logRetryAttempted)
Sets whether to log retry attempts
-
logStackTrace
public RedeliveryPolicy logStackTrace(boolean logStackTrace)
Sets whether to log stacktrace for failed messages.
-
logRetryStackTrace
public RedeliveryPolicy logRetryStackTrace(boolean logRetryStackTrace)
Sets whether to log stacktrace for failed redelivery attempts
-
logHandled
public RedeliveryPolicy logHandled(boolean logHandled)
Sets whether to log errors even if its handled
-
logNewException
public RedeliveryPolicy logNewException(boolean logNewException)
Sets whether errors should be logged when a new exception occurred during handling a previous exception
-
logExhausted
public RedeliveryPolicy logExhausted(boolean logExhausted)
Sets whether to log exhausted errors
-
logExhaustedMessageHistory
public RedeliveryPolicy logExhaustedMessageHistory(boolean logExhaustedMessageHistory)
Sets whether to log exhausted errors including message history
-
logExhaustedMessageBody
public RedeliveryPolicy logExhaustedMessageBody(boolean logExhaustedMessageBody)
Sets whether to log exhausted errors including message body (requires message history to be enabled)
-
delayPattern
public RedeliveryPolicy delayPattern(String delayPattern)
Sets the delay pattern with delay intervals.
-
disableRedelivery
public RedeliveryPolicy disableRedelivery()
Disables redelivery by setting maximum redeliveries to 0.
-
asyncDelayedRedelivery
public RedeliveryPolicy asyncDelayedRedelivery()
Allow asynchronous delayed redelivery.- See Also:
setAsyncDelayedRedelivery(boolean)
-
allowRedeliveryWhileStopping
public RedeliveryPolicy allowRedeliveryWhileStopping(boolean redeliverWhileStopping)
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
public RedeliveryPolicy exchangeFormatterRef(String 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
protected static Random 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
public String getDelayPattern()
-
setDelayPattern
public void setDelayPattern(String delayPattern)
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
public Boolean 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:
isLogExhaustedMessageHistory()
-
setLogExhaustedMessageHistory
public void setLogExhaustedMessageHistory(boolean logExhaustedMessageHistory)
Sets whether exhausted exceptions should be logged with message history included.
-
isLogExhaustedMessageBody
public boolean isLogExhaustedMessageBody()
-
getLogExhaustedMessageBody
public Boolean 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:
isLogExhaustedMessageBody()
-
setLogExhaustedMessageBody
public void setLogExhaustedMessageBody(Boolean logExhaustedMessageBody)
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
public String getExchangeFormatterRef()
-
setExchangeFormatterRef
public void setExchangeFormatterRef(String exchangeFormatterRef)
Sets the reference of the instance ofExchangeFormatter
to generate the log message from exchange.
-
-