camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cecilio Alvarez <cecilio.alva...@hotmail.com>
Subject Re: On exception notify first error.
Date Tue, 26 May 2015 14:44:49 GMT
Thanks for the help.

I came with the following solution:


public class ErrorHandlerNotifier implements Processor{
    
    Logger logger = LoggerFactory.getLogger(ErrorHandlerNotifier.class);
 
    private String destination;
    private final String DEFAULT_DESTINATION = "activemq:MAILING";
        
    private int numberOfRedeliveries;
    private final int DEFAULT_NUMBER_OF_REDELIVERIES = 100;

    public void setMonitoringDestination(String destination) {
        if(destination == null){
            this.destination = DEFAULT_DESTINATION;
            logger.debug("Usign default destination {} for monitoring error
handler.",DEFAULT_DESTINATION);
        }else{
            this.destination = destination;
            logger.debug("Using destination {} for monitoring error
handler.",destination);
        }
    }
    
    public void setMaximumNumberOfRedeliveries(int numberOfRedeliveries) {
        if(numberOfRedeliveries == 0){
            this.numberOfRedeliveries = DEFAULT_NUMBER_OF_REDELIVERIES;
            logger.debug("Using default number of redeliveries :
{}",DEFAULT_NUMBER_OF_REDELIVERIES);
        }else{
            this.numberOfRedeliveries = numberOfRedeliveries;
            logger.debug("Using number of redeliveries :
{}",numberOfRedeliveries);
        }
    }
    public void process(Exchange exchange) throws Exception {
        
        int redeliveryCounter =
exchange.getIn().getHeader("CamelRedeliveryCounter", Integer.class);
       
        //Check if the retry needs to be notified.
        if(redeliveryCounter == numberOfRedeliveries){
            numberOfRedeliveries = numberOfRedeliveries * 2;
            logger.info("Send a notification... ");
            exchange.getIn().setHeader("TooManyRedeliveries",true);
            exchange.getContext().createProducerTemplate().send(destination,
exchange);
        }
    }
}


And Spring:

 <errorHandler id="eh"
                  type="DefaultErrorHandler"
                  onRedeliveryRef="myRetryProcessor">
      <redeliveryPolicy maximumRedeliveries="20"
                        redeliveryDelay="1000" 
                        retryAttemptedLogLevel="WARN"/>
 </errorHandler>

<bean id="myRetryProcessor" class="com.test.ErrorHandlerNotifier">
	<property name="monitoringDestination" value="activemq:MAILING"/>
	<property name="maximumNumberOfRedeliveries" value="200"/>
</bean>

Thanks for the help!



--
View this message in context: http://camel.465427.n5.nabble.com/On-exception-notify-first-error-tp5767385p5767494.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message