1) Definicja ErrorHandler - definiowany na poziomie RouteContext:
public class MyDistributeRouteBuilder extends RouteBuilder {
private static final Logger log = Logger.getLogger(MyDistributeRouteBuilder.class);
public void configure() throws Exception {
errorHandler(deadLetterChannel("direct:distributeError")
// punkt przechowywania
.useOriginalMessage().maximumRedeliveries(2)
// liczba wznowień
.onRedelivery(new MyRedeliverProcessor("MyDistributeRouteBuilder")).redeliveryDelay(3000)
// czas opóźnienia
.backOffMultiplier(2)
// mnożnik opóźnienia między próbami
.logStackTrace(true).loggingLevel(LoggingLevel.INFO)
.logRetryStackTrace(true).logHandled(true));
from("direct:distributeError")
.log(LoggingLevel.INFO, "Forward to a route error handling")
.errorHandler(noErrorHandler())
.to("direct:errorHandling").end();
}
}
2) Definicja doTry - definiowana na wybranym fragmencie trasy:
<route>
<from uri="direct:myroute" />
<log message="myroute - BEGIN"
loggingLevel="INFO" logName="com.blogspot.programmingmt" />
<doTry>
<bean ref="someBean" method="prepareException" />
<doCatch>
<!-- catch multiple exceptions -->
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<camel:setBody>
<!-- <simple resultType="java.lang.Boolean">false</simple> -->
<simple resultType="java.lang.String">Caught exception message: ${exception.message}</simple>
</camel:setBody>
<log message="myroute - EXCEPTION"
loggingLevel="ERROR" logName="com.blogspot.programmingmt" />
</doCatch>
</doTry>
</route>
3) Definicja noErrorHandler - definiowana na poziomie trasy. Wyłącza obsługę błędów.
Java DSL:
from("direct:distributeError")
.log(LoggingLevel.INFO, "Forward to a route error handling")
.errorHandler(noErrorHandler())
.to("direct:errorHandling").end();
Spring DSL:
<route errorHandlerRef="noErrorHandler">
<from uri="direct:myroute" />
<log message="myroute - BEGIN"
loggingLevel="INFO" logName="com.blogspot.programmingmt" />
<from uri="mock:delete" />
</route>