Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: updated text related to ThrottlingExceptionHandler


  • closed: the route will consume messages from the defined endpoint. 
  • open: the route will be suspended and will not consume messages from the defined endpoint.
    • the route is opened when a configurable number of exceptions occurs withing a specified time frame.
  • half-open: the route will perform a check to see if the route can be moved from open to closed. 
    • this will occur by resuming the route and checking for exceptions or by calling an implementation of the ThrottlingExceptionHalfOpenHandler.
      • If an exception is caught when the route is resumed it will re-open, otherwise it will move to the closed state. 
      • If the implemenation of ThrottlingExceptionHalfOpenHandler is provided and the isReadyToBeClosed method returns true the route will be moved to the closed state. Otherwise it will be moved to the open state.

The throttling exception route policy has the following options:






The number of exceptions that must be caught before the circuit controlling the route is opened.



The time range, in milliseconds, in which the number of exceptions must occur in order for the circuit to be opened.



Defines how long the circuit will remain open, in milliseconds, before the circuit is moved into the half-open state.



An optional List<Class<?>> of exceptions. If this option is set, only these exceptions will count towards meeting the failureThreshold. If this list is left as null any exception will be counted toward the failureThreshold.



An optional implementation of the ThrottlingExceptionHalfOpenHandler. When provided, the policy will delegate the handling of the half-open state to this class. If it is left as null, the route will resume during the half open state. It is possible for more than one message to be read from the endpoint when the route is resumed during the half-open state. 



This option (new as of Camel 2.21) allows the circuit to be placed in the open state when set to true. It overrides all other settings and the half open state will not be processed. The circuit will not be moved out of the open state until this option is set to false.

In the example below, a simple route is configured to open after 2 exceptions are thrown within 30 seconds of each other. When 60 seconds have expired the route will be moved into the half-open state. If an implementation of ThrottlingExceptionHalfOpenHandler is not provided, the route will resume. If an exception is caught it will re-open, otherwise it will move ot the closed state. However, it is possible for more than one message to be read from the endpoint during the half-open state. The check performed during the half-open state can will be delegated to the ThrottlingExceptionHalfOpenHandler (if provided)CustomHalfOpenHandler. This class provides an option to check for resources that may be failing independent of resuming the route. 

Code Block
public void configure() throws Exception {
	int threshold = 2;
	long failureWindow = 30000;
	long halfOpenAfter = 60000;

   	ThrottlingExceptionRoutePolicy policy = new ThrottlingExceptionRoutePolicy(threshold, failureWindow, halfOpenAfter, null);
	policy.setHalfOpenHandler(new CustomCloseHandlerCustomHalfOpenHandler());