Understanding Apache Camel Redelivery policy
In previous Apache Camel Exception Handling we had written code to implement exception handling.
A redelivery policy defines rules when Camel Error Handler perform redelivery attempts. For example you can setup rules that state how many times to try redelivery, and the delay in between attempts, and so forth. Suppose we have a scenario where an exception is caused due to network issue, we will want to retry such messages again before the exception is handled.
Apache Camel - Table of Contents
File Transfer Using Java DSL Apache Camel Apache Camel Java DSL + Spring Integration Hello World Example Apache Camel Exception Handling Using Simple Example Apache Camel Redelivery policy using example Integrate Apache Camel and ActiveMQ EIP patterns using Apache Camel Apache Camel Tutorial- Integrate Spring Boot+ Apache Camel Apache Camel Tutorial- Integrate with MySQL DB using SQL query Apache Camel EIP - Splitter and Aggregator pattern Apache Camel Unit Testing Apache Camel + Spring + Quartz Hello World Example Camel application deployment on JBoss Fuse Apache Camel + Apache CXF SOAP Webservices Apache Camel + JAX-RS REST Webservice Apache Camel + CXFRS REST Webservice Apache Camel Routing Slip EIP Pattern Apache Camel Dynamic Router Pattern Apache Camel Load Balancer EIP Pattern Apache Camel Interceptors Apache Camel + Kafka Hello World Example Apache Camel - Marshalling/Unmarshalling XML/JSON Data Example Calling and Consuming Webservices using Apache Camel Apache Camel Tutorial - Send SMTP Email Using Gmail Apache Camel Tutorial - SEDA component Hello World Example Spring Boot + Apache Camel + RabbitMQ - Hello World Example Apache Camel Tutorial - Idempotent Consumer using MemoryIdempotentRepository and FileIdempotentRepository Spring Boot + Apache Camel JDBC component + MySQL - Hello World Example Spring Boot + Apache Camel SQL component + MySQL - Hello World Example Spring Boot + Apache Camel SQL component + Transaction Management Example
Video
This tutorial is explained in the below Youtube Video.Lets Begin
The project in the previous Apache Camel Exception Handling will be the starting point.The project structure will be as follows-

We modify the MyProcessor as follows. We check if the input contains the text "test", then an exception is thrown.
package com.javainuse.processor; import org.apache.camel.Exchange; import org.apache.camel.Processor; import com.javainuse.exception.CamelCustomException; public class MyProcessor implements Processor { public void process(Exchange exchange) throws Exception { String a = exchange.getIn().getBody(String.class); System.out.println("hello " + a); if (a.equalsIgnoreCase("test")) throw new CamelCustomException(); } }
package com.javainuse.route; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import com.javainuse.exception.CamelCustomException; import com.javainuse.processor.MyProcessor; public class SimpleRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { onException(CamelCustomException.class).process(new Processor() { public void process(Exchange exchange) throws Exception { System.out.println("handling ex"); } }).log("Received body ").handled(true); from("file:C:/inputFolder?noop=true").process(new MyProcessor()).to("file:C:/outputFolder"); } }