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 TypeMethodDescriptionvoid
commit
(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint, int polledMessages) protected void
doStop()
int
getLimit()
protected boolean
onRollback
(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint) Rollback occurred.protected void
onSuspend
(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint) The consumer is to be suspended because it exceeded the limitboolean
rollback
(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint, int retryCounter, Exception cause) void
setLimit
(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
begin
Methods 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, 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
-
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:
commit
in interfaceorg.apache.camel.spi.PollingConsumerPollStrategy
- Overrides:
commit
in 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:
rollback
in interfaceorg.apache.camel.spi.PollingConsumerPollStrategy
- Overrides:
rollback
in 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:
doStop
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-