gpt4 book ai didi

记录 Camel 异常并发送到死信 channel

转载 作者:行者123 更新时间:2023-12-04 13:41:27 25 4
gpt4 key购买 nike

我有一条在 Karaf 内运行的 Camel 路线,为此我添加了一个死信 channel 。这是为了处理路由失败的情况,我想保留问题消息并记录原因。我无法将异常抛出回调用应用程序,因为我正在异步处理一些处理。

通过阅读文档并尝试了许多案例,我不清楚如何将异常记录到 Karaf 的日志中并将原始消息存入死信队列。

这是我所拥有的摘录:-

<bean id="deadLetterQueue" class="org.apache.camel.builder.DeadLetterChannelBuilder">
<property name="deadLetterUri" value="activemq:dead.letter.queue"/>
<property name="redeliveryPolicy" ref="redeliveryPolicy"/>
</bean>

<bean id="redeliveryPolicy" class="org.apache.camel.processor.RedeliveryPolicy">
<property name="maximumRedeliveries" value="1"/>
<property name="redeliveryDelay" value="1000"/>
</bean>

<camelContext id="notification" errorHandlerRef="deadLetterQueue"
trace="false" xmlns="http://camel.apache.org/schema/blueprint">
<onException>
<exception>org.xyz.exceptions.unchecked.notificationException</exception>
<log logName="notifications" loggingLevel="ERROR"
message="Exception from notification Camel route" />
</onException>

<route id="DoSomething" errorHandlerRef="deadLetterQueue">
<from uri="activemq:notification.in" />
<log logName="notifications" loggingLevel="TRACE"
message="Notification route initiated" />
<bean ref="NotificationProcessor" method="doStuff" />
</route>
</camelContext>

如果我删除“onException”结构,那么在所有异常情况下,源消息都会出现在死信队列中,但不会被记录。

如果我像上面那样运行它,那么异常跟踪会记录到 Karaf 的日志中(如果它是“notificationException”),但相关的源消息不会回滚到死信队列并消失在以太中(大概就像它认为的那样)我已经在“onException”结构中处理了它)。

查看了不同类型的错误处理程序后,我尝试将内容添加到 DeadLetterChannelBuilder 中,例如...
<property name="logName" value="notifications"/>
<property name="level" value="ERROR"/>

...但这些不是合法属性(property)。

我还觉得必须在 onException 子句中明确列出不同的异常是不正确的。

那么,如何让死信 channel 记录异常跟踪并将消息放入队列?也许死信 channel 不是正确的处理程序 - 在这种情况下,我对自动重新发送并不感兴趣。

感谢您的任何指导,

J。

最佳答案

您可以只使用死信队列的路由,并进行日志记录并发送到 JMS 队列。然后用direct引用这个路由

<property name="deadLetterUri" value="direct:myDLC"/>

<route>
<from uri="direct:myDLC"/>
<log logName="notifications" loggingLevel="ERROR"
message="Exception from notification Camel route" />
<to uri="activemq:dead.letter.queue"/>
</route>

你用的是什么版本的 Camel ?

关于记录 Camel 异常并发送到死信 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13711462/

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