gpt4 book ai didi

java - 如果死信中重新传递失败,Camel 将消息存储在文件组件中

转载 作者:行者123 更新时间:2023-12-02 12:51:48 24 4
gpt4 key购买 nike

我有一个包含 5 行的 xml 文件,如果在处理第三行时发生异常,并且作为死信 channel 的一部分,重新​​传递也会失败,则该文件将被拆分。

MyFile.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()")

ErrorHandlerProcessor

    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>

如何将控制台中打印的失败内容保存为单独的文件?这可能吗?

最佳答案

只需使用文件端点作为死信 channel 而不是日志端点,例如

 errorHandler(deadLetterChannel("file:errors")

关于java - 如果死信中重新传递失败,Camel 将消息存储在文件组件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44574070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com