Class RetryingErrorHandler
java.lang.Object
io.fluxcapacitor.javaclient.tracking.RetryingErrorHandler
- All Implemented Interfaces:
ErrorHandler
- Direct Known Subclasses:
ForeverRetryingErrorHandler
An
ErrorHandler
implementation that retries failed operations a configurable number of times, with optional
propagation or suppression of unrecoverable errors.
This handler is designed for scenarios where transient failures (e.g., network hiccups, temporary service downtime) are expected and recovery is possible through retrying the operation. It allows for detailed control over:
- Which errors should trigger retries (via
errorFilter
) - How many retries to perform and at what delay (via
RetryConfiguration
) - Whether to stop the consumer or continue on final failure
- Whether functional errors should be logged
Retry Logic:
- If the error matches
errorFilter
, theretryFunction
is invoked repeatedly up tomaxRetries
. - If all retries fail:
- And
stopConsumerOnFailure
istrue
, the original error is rethrown, halting tracking. - Otherwise, the error is logged and passed through
invalid reference
RetryConfiguration#getErrorMapper()
- And
- If the error does not match the filter, no retries are performed and the handler either continues or propagates, based on configuration.
Logging Behavior:
- Technical errors are logged at
ERROR
level. FunctionalException
s are logged atWARN
level, iflogFunctionalErrors
istrue
.- Retry success is logged via
RetryConfiguration.successLogger
.
Usage Example:
@Consumer(name = "resilientHandler", errorHandler = RetryingErrorHandler.class)
public class ResilientCommandHandler {
@HandleCommand
void handle(PlaceOrder command) {
// Retries on technical failures before giving up
}
}
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a handler that retries on technical exceptions up to 5 times with a 2-second delay.RetryingErrorHandler
(boolean stopConsumerOnFailure) Constructs a handler with default retry behavior and optional consumer stop behavior.RetryingErrorHandler
(int maxRetries, Duration delay, Predicate<Throwable> errorFilter, boolean stopConsumerOnFailure, boolean logFunctionalErrors) Constructs a handler with detailed retry configuration options.RetryingErrorHandler
(int maxRetries, Duration delay, Predicate<Throwable> errorFilter, boolean stopConsumerOnFailure, boolean logFunctionalErrors, Function<Throwable, ?> errorMapper) Constructs a fully customized retrying handler with retry behavior and error mapping logic.RetryingErrorHandler
(Predicate<Throwable> errorFilter) Constructs a handler with a custom error filter that allows message tracking to continue if the error persists after retries.RetryingErrorHandler
(Predicate<Throwable> errorFilter, boolean stopConsumerOnFailure) Constructs a handler with a custom error filter and optional consumer stop behavior. -
Method Summary
Modifier and TypeMethodDescriptionhandleError
(Throwable error, String errorMessage, Callable<?> retryFunction) Handles the error by retrying the operation if allowed, or propagating/logging based on configuration.protected static boolean
isTechnicalError
(Throwable error) Determines if the error is a technical exception (notFunctionalException
).protected void
Logs the error at the appropriate level based on its type.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.tracking.ErrorHandler
handleError
-
Constructor Details
-
RetryingErrorHandler
public RetryingErrorHandler()Constructs a handler that retries on technical exceptions up to 5 times with a 2-second delay. Consumer is not stopped on failure. -
RetryingErrorHandler
public RetryingErrorHandler(boolean stopConsumerOnFailure) Constructs a handler with default retry behavior and optional consumer stop behavior. -
RetryingErrorHandler
Constructs a handler with a custom error filter that allows message tracking to continue if the error persists after retries. -
RetryingErrorHandler
Constructs a handler with a custom error filter and optional consumer stop behavior. -
RetryingErrorHandler
public RetryingErrorHandler(int maxRetries, Duration delay, Predicate<Throwable> errorFilter, boolean stopConsumerOnFailure, boolean logFunctionalErrors) Constructs a handler with detailed retry configuration options. -
RetryingErrorHandler
public RetryingErrorHandler(int maxRetries, Duration delay, Predicate<Throwable> errorFilter, boolean stopConsumerOnFailure, boolean logFunctionalErrors, Function<Throwable, ?> errorMapper) Constructs a fully customized retrying handler with retry behavior and error mapping logic.
-
-
Method Details
-
handleError
Handles the error by retrying the operation if allowed, or propagating/logging based on configuration. Throws the original error if retries are exhausted and the tracker should stop.- Specified by:
handleError
in interfaceErrorHandler
- Parameters:
error
- the encounteredThrowable
errorMessage
- context about the failureretryFunction
- the operation that failed- Returns:
- the final result or error after retries
-
logError
Logs the error at the appropriate level based on its type. -
isTechnicalError
Determines if the error is a technical exception (notFunctionalException
).
-