public class ThrottlingExceptionRoutePolicy extends RoutePolicySupport implements CamelContextAware
CircuitBreakerLoadBalancer and ThrottlingInflightRoutePolicy
this RoutePolicy will stop consuming from an endpoint based on the type of exceptions that are
thrown and the threshold setting.
the scenario: if a route cannot process data from an endpoint due to problems with resources used by the route
(ie database down) then it will stop consuming new messages from the endpoint by stopping the consumer.
The implementation is comparable to the Circuit Breaker pattern. After a set amount of time, it will move
to a half open state and attempt to determine if the consumer can be started.
There are two ways to determine if a route can be closed after being opened
(1) start the consumer and check the failure threshold
(2) call the ThrottlingExceptionHalfOpenHandler
The second option allows a custom check to be performed without having to take on the possibility of
multiple messages from the endpoint. The idea is that a handler could run a simple test (ie select 1 from dual)
to determine if the processes that cause the route to be open are now availablelogshutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending| Constructor and Description |
|---|
ThrottlingExceptionRoutePolicy(int threshold,
long failureWindow,
long halfOpenAfter,
List<Class<?>> handledExceptions) |
ThrottlingExceptionRoutePolicy(int threshold,
long failureWindow,
long halfOpenAfter,
List<Class<?>> handledExceptions,
boolean keepOpen) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addHalfOpenTimer(Route route) |
protected void |
closeCircuit(Route route) |
String |
dumpState() |
CamelContext |
getCamelContext()
Get the
CamelContext |
int |
getFailures() |
int |
getFailureThreshold() |
long |
getFailureWindow() |
long |
getHalfOpenAfter() |
ThrottlingExceptionHalfOpenHandler |
getHalfOpenHandler() |
boolean |
getKeepOpen() |
long |
getLastFailure() |
long |
getOpenedAt() |
protected void |
halfOpenCircuit(Route route) |
protected boolean |
isThresholdExceeded() |
void |
onExchangeDone(Route route,
Exchange exchange)
|
void |
onInit(Route route)
Callback invoked when the
Route is being initialized |
void |
onStart(Route route)
Callback invoked when the
Route is being started |
protected void |
openCircuit(Route route) |
void |
setCamelContext(CamelContext camelContext)
Injects the
CamelContext |
void |
setFailureThreshold(int failureThreshold) |
void |
setFailureWindow(long failureWindow) |
void |
setHalfOpenAfter(long halfOpenAfter) |
void |
setHalfOpenHandler(ThrottlingExceptionHalfOpenHandler halfOpenHandler) |
void |
setKeepOpen(boolean keepOpen) |
doStart, doStop, getExceptionHandler, handleException, onExchangeBegin, onRemove, onResume, onStop, onSuspend, resumeOrStartConsumer, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, stopRouteAsync, suspendOrStopConsumer, suspendRoute, suspendRoutedoResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendpublic ThrottlingExceptionRoutePolicy(int threshold, long failureWindow, long halfOpenAfter, List<Class<?>> handledExceptions)
public ThrottlingExceptionRoutePolicy(int threshold, long failureWindow, long halfOpenAfter, List<Class<?>> handledExceptions, boolean keepOpen)
public void setCamelContext(CamelContext camelContext)
CamelContextAwareCamelContextsetCamelContext in interface CamelContextAwarecamelContext - the Camel contextpublic CamelContext getCamelContext()
CamelContextAwareCamelContextgetCamelContext in interface CamelContextAwarepublic void onInit(Route route)
RoutePolicyRoute is being initializedonInit in interface RoutePolicyonInit in class RoutePolicySupportroute - the route being initializedpublic void onStart(Route route)
RoutePolicyRoute is being startedonStart in interface RoutePolicyonStart in class RoutePolicySupportroute - the route being startedpublic void onExchangeDone(Route route, Exchange exchange)
RoutePolicyExchange is done being routed, where it started from the given Route
Notice this callback is invoked when the Exchange is done and the Route is the route where
the Exchange was started. Most often its also the route where the exchange is done. However its
possible to route an Exchange to other routes using endpoints such as
direct or seda. Bottom line is that the Route parameter may not be the endpoint
route and thus why we state its the starting route.onExchangeDone in interface RoutePolicyonExchangeDone in class RoutePolicySupportroute - the route where the exchange started fromexchange - the created exchangeprotected boolean isThresholdExceeded()
protected void openCircuit(Route route)
protected void addHalfOpenTimer(Route route)
protected void halfOpenCircuit(Route route)
protected void closeCircuit(Route route)
public ThrottlingExceptionHalfOpenHandler getHalfOpenHandler()
public void setHalfOpenHandler(ThrottlingExceptionHalfOpenHandler halfOpenHandler)
public boolean getKeepOpen()
public void setKeepOpen(boolean keepOpen)
public int getFailureThreshold()
public void setFailureThreshold(int failureThreshold)
public long getFailureWindow()
public void setFailureWindow(long failureWindow)
public long getHalfOpenAfter()
public void setHalfOpenAfter(long halfOpenAfter)
public int getFailures()
public long getLastFailure()
public long getOpenedAt()
Apache Camel