Package org.apache.camel.throttling
Class ThrottlingExceptionRoutePolicy
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.RoutePolicySupport
org.apache.camel.throttling.ThrottlingExceptionRoutePolicy
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.CamelContextAware
,org.apache.camel.RouteAware
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.HasCamelContext
,org.apache.camel.spi.RoutePolicy
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
@Metadata(label="bean",
description="A throttle based RoutePolicy which is modelled after the circuit breaker and will stop consuming from an endpoint based on the type of exceptions that are thrown and the threshold settings.",
annotations="interfaceName=org.apache.camel.spi.RoutePolicy")
@Configurer(metadataOnly=true)
public class ThrottlingExceptionRoutePolicy
extends RoutePolicySupport
implements org.apache.camel.CamelContextAware, org.apache.camel.RouteAware
Modeled after the circuit breaker
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 available-
Field Summary
Fields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
-
Constructor Summary
ConstructorsConstructorDescriptionThrottlingExceptionRoutePolicy
(int threshold, long failureWindow, long halfOpenAfter, List<Class<?>> handledExceptions) ThrottlingExceptionRoutePolicy
(int threshold, long failureWindow, long halfOpenAfter, List<Class<?>> handledExceptions, boolean keepOpen) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addHalfOpenTimer
(org.apache.camel.Route route) protected void
closeCircuit
(org.apache.camel.Route route) protected void
doInit()
protected void
doStop()
org.apache.camel.CamelContext
int
int
long
long
boolean
long
long
org.apache.camel.Route
getRoute()
org.apache.camel.LoggingLevel
int
protected void
halfOpenCircuit
(org.apache.camel.Route route) protected boolean
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
setExceptions
(String exceptions) void
setFailureThreshold
(int failureThreshold) void
setFailureWindow
(long failureWindow) void
setHalfOpenAfter
(long halfOpenAfter) void
setHalfOpenHandler
(ThrottlingExceptionHalfOpenHandler halfOpenHandler) void
setKeepOpen
(boolean keepOpen) void
setRoute
(org.apache.camel.Route route) void
setStateLoggingLevel
(String stateLoggingLevel) void
setStateLoggingLevel
(org.apache.camel.LoggingLevel stateLoggingLevel) Methods inherited from class org.apache.camel.support.RoutePolicySupport
controller, getExceptionHandler, handleException, onExchangeBegin, onRemove, onResume, onStop, onSuspend, resumeOrStartConsumer, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, stopRouteAsync, suspendOrStopConsumer, suspendRoute, suspendRoute
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doStart, doSuspend, fail, getInternalLock, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.camel.Service
build, close, init, start, stop
Methods inherited from interface org.apache.camel.ShutdownableService
shutdown
Methods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
Methods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Constructor Details
-
ThrottlingExceptionRoutePolicy
public ThrottlingExceptionRoutePolicy() -
ThrottlingExceptionRoutePolicy
-
ThrottlingExceptionRoutePolicy
-
-
Method Details
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext camelContext) - Specified by:
setCamelContext
in interfaceorg.apache.camel.CamelContextAware
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()- Specified by:
getCamelContext
in interfaceorg.apache.camel.spi.HasCamelContext
-
getRoute
public org.apache.camel.Route getRoute()- Specified by:
getRoute
in interfaceorg.apache.camel.RouteAware
-
setRoute
public void setRoute(org.apache.camel.Route route) - Specified by:
setRoute
in interfaceorg.apache.camel.RouteAware
-
getThrottledExceptions
-
getExceptions
-
setExceptions
-
doInit
- Overrides:
doInit
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
onInit
public void onInit(org.apache.camel.Route route) - Specified by:
onInit
in interfaceorg.apache.camel.spi.RoutePolicy
- Overrides:
onInit
in classRoutePolicySupport
-
onStart
public void onStart(org.apache.camel.Route route) - Specified by:
onStart
in interfaceorg.apache.camel.spi.RoutePolicy
- Overrides:
onStart
in classRoutePolicySupport
-
doStop
- Overrides:
doStop
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
onExchangeDone
public void onExchangeDone(org.apache.camel.Route route, org.apache.camel.Exchange exchange) - Specified by:
onExchangeDone
in interfaceorg.apache.camel.spi.RoutePolicy
- Overrides:
onExchangeDone
in classRoutePolicySupport
-
isThresholdExceeded
protected boolean isThresholdExceeded() -
openCircuit
protected void openCircuit(org.apache.camel.Route route) -
addHalfOpenTimer
protected void addHalfOpenTimer(org.apache.camel.Route route) -
halfOpenCircuit
protected void halfOpenCircuit(org.apache.camel.Route route) -
closeCircuit
protected void closeCircuit(org.apache.camel.Route route) -
getStateAsString
-
dumpState
-
getHalfOpenHandler
-
setHalfOpenHandler
-
getKeepOpen
public boolean getKeepOpen() -
setKeepOpen
public void setKeepOpen(boolean keepOpen) -
getFailureThreshold
public int getFailureThreshold() -
setFailureThreshold
public void setFailureThreshold(int failureThreshold) -
getFailureWindow
public long getFailureWindow() -
setFailureWindow
public void setFailureWindow(long failureWindow) -
getHalfOpenAfter
public long getHalfOpenAfter() -
setHalfOpenAfter
public void setHalfOpenAfter(long halfOpenAfter) -
getFailures
public int getFailures() -
getSuccess
public int getSuccess() -
getLastFailure
public long getLastFailure() -
getOpenedAt
public long getOpenedAt() -
getStateLoggingLevel
public org.apache.camel.LoggingLevel getStateLoggingLevel() -
setStateLoggingLevel
public void setStateLoggingLevel(org.apache.camel.LoggingLevel stateLoggingLevel) -
setStateLoggingLevel
-