org.apache.camel.impl
Class LimitedPollingConsumerPollStrategy

java.lang.Object
  extended by org.apache.camel.impl.DefaultPollingConsumerPollStrategy
      extended by org.apache.camel.impl.LimitedPollingConsumerPollStrategy
All Implemented Interfaces:
Service, PollingConsumerPollStrategy

public class LimitedPollingConsumerPollStrategy
extends DefaultPollingConsumerPollStrategy
implements 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.

Version:

Field Summary
 
Fields inherited from class org.apache.camel.impl.DefaultPollingConsumerPollStrategy
log
 
Constructor Summary
LimitedPollingConsumerPollStrategy()
           
 
Method Summary
 void commit(Consumer consumer, Endpoint endpoint, int polledMessages)
          Called when poll is completed successfully
 int getLimit()
           
protected  boolean onRollback(Consumer consumer, Endpoint endpoint)
          Rollback occurred.
protected  void onSuspend(Consumer consumer, Endpoint endpoint)
          The consumer is to be suspended because it exceeded the limit
 boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception cause)
          Called when poll failed
 void setLimit(int limit)
          Sets the limit for how many straight rollbacks causes this strategy to suspend the fault consumer.
 void start()
          Starts the service
 void stop()
          Stops the service
 
Methods inherited from class org.apache.camel.impl.DefaultPollingConsumerPollStrategy
begin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LimitedPollingConsumerPollStrategy

public LimitedPollingConsumerPollStrategy()
Method Detail

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(Consumer consumer,
                   Endpoint endpoint,
                   int polledMessages)
Description copied from interface: PollingConsumerPollStrategy
Called when poll is completed successfully

Specified by:
commit in interface PollingConsumerPollStrategy
Overrides:
commit in class DefaultPollingConsumerPollStrategy
Parameters:
consumer - the consumer
endpoint - the endpoint being consumed
polledMessages - number of messages polled, will be 0 if no message was polled at all.

rollback

public boolean rollback(Consumer consumer,
                        Endpoint endpoint,
                        int retryCounter,
                        Exception cause)
                 throws Exception
Description copied from interface: PollingConsumerPollStrategy
Called when poll failed

Specified by:
rollback in interface PollingConsumerPollStrategy
Overrides:
rollback in class DefaultPollingConsumerPollStrategy
Parameters:
consumer - the consumer
endpoint - the endpoint being consumed
retryCounter - current retry attempt, starting from 0.
cause - the caused exception
Returns:
whether to retry immediately or not. Return false to ignore the problem, true to try immediately again
Throws:
Exception - can be used to rethrow the caused exception. Notice that thrown an exception will terminate the scheduler and thus Camel will not trigger again. So if you want to let the scheduler to continue to run then do not throw any exception from this method.

onSuspend

protected void onSuspend(Consumer consumer,
                         Endpoint endpoint)
                  throws Exception
The consumer is to be suspended because it exceeded the limit

Parameters:
consumer - the consumer
endpoint - the endpoint
Throws:
Exception - is thrown if error suspending the consumer

onRollback

protected boolean onRollback(Consumer consumer,
                             Endpoint endpoint)
                      throws Exception
Rollback occurred.

Parameters:
consumer - the consumer
endpoint - 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()
           throws Exception
Description copied from interface: Service
Starts the service

Specified by:
start in interface Service
Throws:
Exception - is thrown if starting failed

stop

public void stop()
          throws Exception
Description copied from interface: Service
Stops the service

Specified by:
stop in interface Service
Throws:
Exception - is thrown if stopping failed


Apache CAMEL