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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    commit(org.apache.camel.Consumer consumer, org.apache.camel.Endpoint endpoint, int polledMessages)
     
    int
     
    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 limit
    boolean
    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.
    void
     
    void
     

    Methods inherited from class org.apache.camel.support.DefaultPollingConsumerPollStrategy

    begin

    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
  • 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 interface org.apache.camel.spi.PollingConsumerPollStrategy
      Overrides:
      commit in class org.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 interface org.apache.camel.spi.PollingConsumerPollStrategy
      Overrides:
      rollback in class org.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 consumer
      endpoint - 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 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()
      Specified by:
      start in interface org.apache.camel.Service
    • stop

      public void stop()
      Specified by:
      stop in interface org.apache.camel.Service