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 availablelog
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
Constructor and Description |
---|
ThrottlingExceptionRoutePolicy(int threshold,
long failureWindow,
long halfOpenAfter,
List<Class<?>> handledExceptions) |
Modifier and Type | Method and Description |
---|---|
protected void |
closeCircuit(Route route) |
String |
dumpState() |
CamelContext |
getCamelContext()
Get the
CamelContext |
int |
getFailures() |
int |
getFailureThreshold() |
long |
getFailureWindow() |
long |
getHalfOpenAfter() |
ThrottlingExceptionHalfOpenHandler |
getHalfOpenHandler() |
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 |
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) |
doStart, doStop, getExceptionHandler, handleException, onExchangeBegin, onRemove, onResume, onStart, onStop, onSuspend, resumeOrStartConsumer, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, stopRouteAsync, suspendOrStopConsumer, suspendRoute, suspendRoute
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
public ThrottlingExceptionRoutePolicy(int threshold, long failureWindow, long halfOpenAfter, List<Class<?>> handledExceptions)
public void setCamelContext(CamelContext camelContext)
CamelContextAware
CamelContext
setCamelContext
in interface CamelContextAware
camelContext
- the Camel contextpublic CamelContext getCamelContext()
CamelContextAware
CamelContext
getCamelContext
in interface CamelContextAware
public void onInit(Route route)
RoutePolicy
Route
is being initializedonInit
in interface RoutePolicy
onInit
in class RoutePolicySupport
route
- the route being initializedpublic void onExchangeDone(Route route, Exchange exchange)
RoutePolicy
Exchange
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 RoutePolicy
onExchangeDone
in class RoutePolicySupport
route
- the route where the exchange started fromexchange
- the created exchangeprotected boolean isThresholdExceeded()
protected void openCircuit(Route route)
protected void halfOpenCircuit(Route route)
protected void closeCircuit(Route route)
public ThrottlingExceptionHalfOpenHandler getHalfOpenHandler()
public void setHalfOpenHandler(ThrottlingExceptionHalfOpenHandler halfOpenHandler)
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