问题描述
我有一条骆驼路线,在卡拉夫内运行,为此我添加了一个死信通道。这是为了处理路由失败的情况,我想保留问题消息并记录原因。我不能将异常返回到调用应用程序,因为我正在异步处理一些处理。从阅读文档并尝试一些案例,它不清楚对我来说,如何将异常记录到Karaf的日志中,并将原始消息存入死信队列中。
这是一个摘录,我已经得到: p>
< bean id =deadLetterQueueclass =org.apache.camel.builder.DeadLetterChannelBuilder>
< property name =deadLetterUrivalue =activemq:dead.letter.queue/>
< property name =redeliveryPolicyref =redeliveryPolicy/>
< / bean>
< bean id =redeliveryPolicyclass =org.apache.camel.processor.RedeliveryPolicy>
< property name =maximumRedeliveriesvalue =1/>
< property name =redeliveryDelayvalue =1000/>
< / bean>
< camelContext id =notificationerrorHandlerRef =deadLetterQueue
trace =falsexmlns =http://camel.apache.org/schema/blueprint>
< onException>
< exception> org.xyz.exceptions.unchecked.notificationException< / exception>
< log logName =notificationsloggingLevel =ERROR
message =通知骆驼路由异常/>
< / onException>
< route id =DoSomethingerrorHandlerRef =deadLetterQueue>
< from uri =activemq:notification.in/>
< log logName =notificationsloggingLevel =TRACE
message =通知路由启动/>
< bean ref =NotificationProcessormethod =doStuff/>
< / route>
< / camelContext>
如果我删除onException结构,那么在所有异常情况下,源消息都会出现在死信队列但未记录。
如果我按照上述方式运行它,则异常跟踪将记录到Karaf的日志中(如果它是notificationException),但是相关联的源消息不会回滚到死信队列,并消失在以太(可能是因为它认为我在onException结构中处理它)。
看过不同类型的错误处理程序后,我尝试将事情添加到DeadLetterChannelBuilder中,例如...
< property name =logNamevalue =notifications/>
< property name =levelvalue =ERROR/>
...但这些不属于合法属性。
它也让我知道,必须在onException子句中明确列出不同的异常是不正确的。
那么,如何让死者信号通道记录异常跟踪以及将消息放入队列?也许死信通道不是正确的处理程序 - 在这种情况下,我并不关心自动重新投递。
感谢任何指导,
J。
您只能使用路由作为死信队列,做日志记录并发送到JMS队列。然后直接使用这条路线
< property name =deadLetterUrivalue =direct:myDLC/> ;
< route>
< from uri =direct:myDLC/>
< log logName =notificationsloggingLevel =ERROR
message =通知骆驼路由异常/>
< to uri =activemq:dead.letter.queue/>
< / route>
您使用的骆驼版本是多少?
I have a Camel route, running within Karaf, for which I've added a Dead Letter Channel. This is to handle cases where the route fails and I want to keep the problem message and log the cause. I can't throw the exception back to the calling application as I'm handling some processing asynchronously.
From reading the documentation and trying a number of cases, it's not clear to me how to both log the exception into Karaf's log and deposit the original message onto the dead letter queue.
Here's an excerpt of what I've got:-
<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>
If I remove the "onException" structure then, in all exception cases, the source message appears on the dead letter queue but isn't logged.
If I run it as above then the exception trace is logged into Karaf's log (if it is a "notificationException") but the associated source message is not rolled back to the dead letter queue and disappears into the ether (presumably as it thinks I've handled it within the "onException" structure).
Having looked at the different sorts of error handlers, I tried instead adding things to the DeadLetterChannelBuilder such as...
<property name="logName" value="notifications"/>
<property name="level" value="ERROR"/>
...but these aren't legal properties.
It also strikes me that having to list the different exceptions explicitly in the onException clause can't be correct.
So, how do I get the dead letter channel to log the exception trace as well as putting the message onto the queue? Perhaps the dead letter channel isn't the correct handler - I'm not really interested in automatic redelivery in this case.
Thanks for any guidance,
J.
You can just use a route for the dead letter queue, and do logging and sending to JMS queue. And then use direct to refer to this route
<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>
What version of Camel are you using?
这篇关于记录骆驼异常并发送到死信通道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!