我有一个routeContext,我正在尝试确定以下内容。如果JMSXDeliveryCount(消息属性)小于5,我想回滚。如果它大于5,我想记录一条消息并离开。
以下是我的routeContext:
<routeContext id="inbound-errorhandler-route" xmlns="http://camel.apache.org/schema/spring">
<route id="errorhandler">
<from uri="direct:inboundErrorHandler" id="errorHandlerDirect"/>
<choice>
<when>
<simple>${exchangeProperty.JMSXDeliveryCount} >= 5</simple>
<log message="Message retry attempts exhausted, retry count: {{exchangeProperty.JMSXDeliveryCount}}. Not rolling back: ${body}" loggingLevel="ERROR" logName="CamelContext-Route"/>
</when>
<otherwise>
<log message="Caught Unknown Exception - Camel Context route processing - failed : ${body}"
loggingLevel="ERROR" logName="CamelContext-Route"/>
<rollback message="The current message was marked for Rollback, retry count: {{exchangeProperty.JMSXDeliveryCount}}. Please see redelivery policy for re-attempts."/>
</otherwise>
</choice>
</route>
</routeContext>
但是,我永远不会输入第一个选项,并且在回滚的日志消息中,deliveryCount没有更新。它只是显示为纯文本{exchangeProperty.JMSXDeliveryCount}
。
如何正确获取消息属性,特别是JMSXDeliveryCount,以及如何对该属性做出决定?
我正在使用Camel 2.15.2
答案 0 :(得分:2)
要解决我使用纯文本的问题,我必须使用美元符号和括号来引用简单括号中的对象:
<simple>${header.JMSXDeliveryCount} >= 5 </simple>
我还需要使用头对象,而不是exchangeProperty来引用JMS传送计数。
<routeContext id="inbound-errorhandler-route" xmlns="http://camel.apache.org/schema/spring">
<route id="errorhandler">
<from uri="direct:inboundErrorHandler" id="errorHandlerDirect"/>
<choice>
<when>
<simple>${header.JMSXDeliveryCount} >= 5</simple>
<log message="Message retry attempts exhausted, retry count: ${header.JMSXDeliveryCount}. Not rolling back. Message body: ${body}" loggingLevel="ERROR" logName="CamelContext-Route"/>
</when>
<otherwise>
<log message="Caught Unknown Exception - Camel Context route processing - failed, retry count: ${header.JMSXDeliveryCount}. Rolling back. Message body: ${body}"
loggingLevel="ERROR" logName="CamelContext-Route"/>
<rollback message="The current message was marked for Rollback. Please see redelivery policy for re-attempts."/>
</otherwise>
</choice>
</route>
</routeContext>