我有一个包含5行的xml文件正在拆分,如果在处理第三行时发生异常,则重新传递也会作为死信通道的一部分失败。
<orders>
<order>
<orderid>1</orderid>
</order>
<order>
<orderid>2</orderid>
</order>
<order>
<order> //Have not closed order intentionally to get a exception
<order>
<orderid>4</orderid>
</order>
<order>
<orderid>5</orderid>
</order>
</orders>
errorHandler(deadLetterChannel("log:Error Occured!!!!")
.onExceptionOccurred(new ErrorHandlerProcessor())
.useOriginalMessage()
.allowRedeliveryWhileStopping(true)
.maximumRedeliveries(10)
.redeliveryDelay(2000)
.retryAttemptedLogLevel(LoggingLevel.INFO));
from("file:E:/camel")
.routeId("File_Pickup_Route")
.split(body().tokenizeXML("order", "orders"))
.convertBodyTo(String.class)
.process(new SplitProcessor())
.convertBodyTo(File.class)
.bean(MyBean.class,"saveMetaData()")
public class ErrorHandlerProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
System.out.println("\n\n Inside My Error Handler Processor()");
try {
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
exchange.getIn().setHeader("FailedBecause", cause.getMessage());
} catch (Exception e) {
System.out.println(e.printstacktrace());
}
22:47:41,094 INFO [Error Occured!!!!] (Camel (FilePickup) thread #0 - file://E:/camel) Exchange[ExchangePattern: InOnly, BodyType: String, Body: <order>
<orderid>3</orderid>
<order>
如何将作为单独文件在控制台中打印的失败内容保存?那可能吗?
答案 0 :(得分:1)
只需使用文件端点作为死信通道而不是日志端点,例如
errorHandler(deadLetterChannel("file:errors")