Package org.apache.camel.impl.engine
Class LimitedPollingConsumerPollStrategy
java.lang.Object
org.apache.camel.support.DefaultPollingConsumerPollStrategy
org.apache.camel.impl.engine.LimitedPollingConsumerPollStrategy
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.Service,org.apache.camel.spi.PollingConsumerPollStrategy
public class LimitedPollingConsumerPollStrategy
extends org.apache.camel.support.DefaultPollingConsumerPollStrategy
implements org.apache.camel.Service
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.DefaultPollingConsumerPollStrategy
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcommit(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint, int polledMessages) 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.voidstart()voidstop()Methods inherited from class org.apache.camel.support.DefaultPollingConsumerPollStrategy
beginMethods 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
-
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 or not to retry immediately, is default false
- Throws:
Exception- can be thrown in case something goes wrong
-
start
public void start()- Specified by:
startin interfaceorg.apache.camel.Service
-
stop
public void stop()- Specified by:
stopin interfaceorg.apache.camel.Service
-