public class ThrottlingExceptionRoutePolicy extends RoutePolicySupport implements org.apache.camel.CamelContextAware
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 availableConstructor 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(org.apache.camel.Route route) |
protected void |
closeCircuit(org.apache.camel.Route route) |
String |
dumpState() |
org.apache.camel.CamelContext |
getCamelContext() |
int |
getFailures() |
int |
getFailureThreshold() |
long |
getFailureWindow() |
long |
getHalfOpenAfter() |
ThrottlingExceptionHalfOpenHandler |
getHalfOpenHandler() |
boolean |
getKeepOpen() |
long |
getLastFailure() |
long |
getOpenedAt() |
protected void |
halfOpenCircuit(org.apache.camel.Route route) |
protected boolean |
isThresholdExceeded() |
void |
onExchangeDone(org.apache.camel.Route route,
org.apache.camel.Exchange exchange) |
void |
onInit(org.apache.camel.Route route) |
void |
onStart(org.apache.camel.Route route) |
protected void |
openCircuit(org.apache.camel.Route route) |
void |
setCamelContext(org.apache.camel.CamelContext camelContext) |
void |
setFailureThreshold(int failureThreshold) |
void |
setFailureWindow(long failureWindow) |
void |
setHalfOpenAfter(long halfOpenAfter) |
void |
setHalfOpenHandler(ThrottlingExceptionHalfOpenHandler halfOpenHandler) |
void |
setKeepOpen(boolean keepOpen) |
controller, doStart, doStop, getExceptionHandler, handleException, onExchangeBegin, onRemove, onResume, onStop, onSuspend, resumeOrStartConsumer, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, stopRouteAsync, suspendOrStopConsumer, suspendRoute, suspendRoute
build, doBuild, doFail, doInit, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public ThrottlingExceptionRoutePolicy(int threshold, long failureWindow, long halfOpenAfter, List<Class<?>> handledExceptions)
public void setCamelContext(org.apache.camel.CamelContext camelContext)
setCamelContext
in interface org.apache.camel.CamelContextAware
public org.apache.camel.CamelContext getCamelContext()
getCamelContext
in interface org.apache.camel.CamelContextAware
public void onInit(org.apache.camel.Route route)
onInit
in interface org.apache.camel.spi.RoutePolicy
onInit
in class RoutePolicySupport
public void onStart(org.apache.camel.Route route)
onStart
in interface org.apache.camel.spi.RoutePolicy
onStart
in class RoutePolicySupport
public void onExchangeDone(org.apache.camel.Route route, org.apache.camel.Exchange exchange)
onExchangeDone
in interface org.apache.camel.spi.RoutePolicy
onExchangeDone
in class RoutePolicySupport
protected boolean isThresholdExceeded()
protected void openCircuit(org.apache.camel.Route route)
protected void addHalfOpenTimer(org.apache.camel.Route route)
protected void halfOpenCircuit(org.apache.camel.Route route)
protected void closeCircuit(org.apache.camel.Route route)
public String dumpState()
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