You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Cecilio Alvarez <ce...@hotmail.com> on 2015/05/21 16:02:19 UTC
On exception notify first error.
Hello,
is there a way on the on exception or in the error handler to send a message
one time and keep retrying?
Something like this but with error handler or on exception.
<route>
<from uri="activemq:in"/>
<doTry>
<throw new="sql.Exception"/>
<doCatch>
<exception>java.sql.SQLException</exception>
<choice>
<when>
<simple>${header.Reported} == null</simple>
<setHeader headerName="Reported">
<simple>true</simple>
</setHeader>
<multicast>
<to uri="activemq:NOTIFY"/>
<to uri="activemq:in"/>
</multicast>
</when>
<otherwise>
<to uri="activemq:in"/>
</otherwise>
</choice>
</doCatch>
</doTry>
</route>
Any suggestion will be appreciated.
Cecilio.
--
View this message in context: http://camel.465427.n5.nabble.com/On-exception-notify-first-error-tp5767385.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: On exception notify first error.
Posted by Cecilio Alvarez <ce...@hotmail.com>.
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.
Re: On exception notify first error.
Posted by Andrew Block <an...@gmail.com>.
Hi,
You can use a combination of the retryWhile property of onException to allow for indefinite retrying. In addition, you can also use the onRedelivery property to define a custom process to perform action prior to the redelivery of a message. A ProducerTemplate can be used to send to a downstream process.
- Andy
--
Andrew Block
On May 21, 2015 at 9:02:33 AM, Cecilio Alvarez (cecilio.alvarez@hotmail.com) wrote:
Hello,
is there a way on the on exception or in the error handler to send a message
one time and keep retrying?
Something like this but with error handler or on exception.
<route>
<from uri="activemq:in"/>
<doTry>
<throw new="sql.Exception"/>
<doCatch>
<exception>java.sql.SQLException</exception>
<choice>
<when>
<simple>${header.Reported} == null</simple>
<setHeader headerName="Reported">
<simple>true</simple>
</setHeader>
<multicast>
<to uri="activemq:NOTIFY"/>
<to uri="activemq:in"/>
</multicast>
</when>
<otherwise>
<to uri="activemq:in"/>
</otherwise>
</choice>
</doCatch>
</doTry>
</route>
Any suggestion will be appreciated.
Cecilio.
--
View this message in context: http://camel.465427.n5.nabble.com/On-exception-notify-first-error-tp5767385.html
Sent from the Camel - Users mailing list archive at Nabble.com.