Searching...
Sunday, 25 May 2014

Camel DeadLetterChannel errorhandler Example

03:05
Camel supports the Dead Letter Channel from EIP patterns to handle errors. Camel will move the Exchange data in case any exceptions to Dead Letter channel. In this example we will see Route Builder error handler is moving the exchange data to dead letter channel. For testing this While moving the files from source to destination we are throwing exception.
package com.vinod.test;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.main.Main;
public class ErrorHandlerTest {
    public static void main(String... args) throws Exception {
        Main main = new Main();
        main.enableHangupSupport();
        main.addRouteBuilder(new TestRoute());
        main.run(args);
    }
}

class TestRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        errorHandler(deadLetterChannel("file:deadletter"));
        from("file:source").process(new Processor() {
            public void process(Exchange exchange) throws Exception {
                throw new RuntimeException();
            }
        }).to("file:destination");
    }
}

0 comments: