Package org.apache.camel.impl.engine
Class LimitedPollingConsumerPollStrategy
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.DefaultPollingConsumerPollStrategy
org.apache.camel.impl.engine.LimitedPollingConsumerPollStrategy
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.Service,org.apache.camel.ShutdownableService,org.apache.camel.spi.PollingConsumerPollStrategy,org.apache.camel.StatefulService,org.apache.camel.SuspendableService
public class LimitedPollingConsumerPollStrategy
extends org.apache.camel.support.DefaultPollingConsumerPollStrategy
A
PollingConsumerPollStrategy which supports suspending consumers if they failed for X
number of times in a row.
If Camel cannot successfully consumer from a given consumer, then after X consecutive failed attempts the consumer
will be suspended/stopped. This prevents the log to get flooded with failed attempts, for example during nightly
runs.-
Field Summary
Fields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcommit(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint, int polledMessages) protected voiddoStop()intgetLimit()protected booleanonRollback(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint) Rollback occurred.protected voidonSuspend(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint) The consumer is to be suspended because it exceeded the limitbooleanrollback(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint, int retryCounter, Exception cause) voidsetLimit(int limit) Sets the limit for how many straight rollbacks causes this strategy to suspend the fault consumer.Methods inherited from class org.apache.camel.support.DefaultPollingConsumerPollStrategy
beginMethods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doInit, 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, suspendMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.camel.Service
build, close, init, start, stopMethods inherited from interface org.apache.camel.ShutdownableService
shutdownMethods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Constructor Details
-
LimitedPollingConsumerPollStrategy
public LimitedPollingConsumerPollStrategy()
-
-
Method Details
-
getLimit
public int getLimit() -
setLimit
public void setLimit(int limit) Sets the limit for how many straight rollbacks causes this strategy to suspend the fault consumer. When the consumer has been suspended, it has to be manually resumed/started to be active again. The limit is by default 3.- Parameters:
limit- the limit
-
commit
public void commit(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint, int polledMessages) - Specified by:
commitin interfaceorg.apache.camel.spi.PollingConsumerPollStrategy- Overrides:
commitin classorg.apache.camel.support.DefaultPollingConsumerPollStrategy
-
rollback
public boolean rollback(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint, int retryCounter, Exception cause) throws Exception - Specified by:
rollbackin interfaceorg.apache.camel.spi.PollingConsumerPollStrategy- Overrides:
rollbackin classorg.apache.camel.support.DefaultPollingConsumerPollStrategy- Throws:
Exception
-
onSuspend
protected void onSuspend(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint) throws Exception The consumer is to be suspended because it exceeded the limit- Parameters:
consumer- the consumerendpoint- the endpoint- Throws:
Exception- is thrown if error suspending the consumer
-
onRollback
protected boolean onRollback(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint) throws Exception Rollback occurred.- Parameters:
consumer- the consumerendpoint- the endpoint- Returns:
- whether to retry immediately, is default false
- Throws:
Exception- can be thrown in case something goes wrong
-
doStop
- Overrides:
doStopin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-