Java 骆驼的再交付政策
我有一个小的路由,我想使用自定义的重新传递策略来重复向端点发送消息,但是这种行为非常奇怪。看起来,重新交付策略只是在重复一个错误抛出。我试图将所有exchange发送到路由的开头,但策略不起作用,因为每次都会创建:Java 骆驼的再交付政策,java,xml,apache-camel,Java,Xml,Apache Camel,我有一个小的路由,我想使用自定义的重新传递策略来重复向端点发送消息,但是这种行为非常奇怪。看起来,重新交付策略只是在重复一个错误抛出。我试图将所有exchange发送到路由的开头,但策略不起作用,因为每次都会创建: <route id="sampleRoute"> <from uri="direct:anotheRoute" /> <to uri="nmr:kaboom" />
<route id="sampleRoute">
<from uri="direct:anotheRoute" />
<to uri="nmr:kaboom" />
<choice>
<when>
<xpath>//result = 'true'</xpath>
<to uri="direct:anotherAnotherRoute" />
</when>
<otherwise>
<throwException ref="redeliveryException" />
</otherwise>
</choice>
<onException>
<exception>java.net.SocketException</exception>
<exception>java.net.ConnectException</exception>
<exception>my.custom.error.RedeliveryException</exception>
<redeliveryPolicy ref="customRedeliveryPolicy" />
<to uri="direct:anotheRoute" />
</onException>
</route>
这并不奇怪,Camel的错误处理程序和重新交付是从失败的步骤开始执行的,而不是从路由的开始 你可以不用再次抛出错误调用direct:anotherRoute,唯一的问题是如果你这样做太频繁,你的调用堆栈可能会变得太深
您可以做的是将nmr:kaboom放入一个单独的路由,并将其配置为具有noErrorHandler,然后从第一个路由使用direct:,调用它,然后错误处理程序可以从一开始重新传递整个路由。这并不奇怪,Camel的错误处理程序和重新传递从失败的步骤开始执行,不是从路线的开始 你可以不用再次抛出错误调用direct:anotherRoute,唯一的问题是如果你这样做太频繁,你的调用堆栈可能会变得太深
相反,您可以将nmr:kaboom放入一个单独的路由中,并将其配置为具有noErrorHandler,然后从第一个路由使用direct:,调用它,然后错误处理程序可以从一开始重新传递整个路由。感谢您的解释。我将发布正确答案:
<route id="sampleRoute">
<from uri="direct:anotheRoute" />
<to uri="direct:kaboom" />
<onException>
<exception>java.net.SocketException</exception>
<exception>java.net.ConnectException</exception>
<exception>my.custom.error.RedeliveryException</exception>
<redeliveryPolicy ref="customRedeliveryPolicy" />
</onException>
</route>
<route errorHandlerRef="noErrorHandler">
<from uri="direct:kaboom />
<to uri="nmr:kaboom/>
<choice>
<when>
<xpath>//result = 'true'</xpath>
<to uri="direct:anotherAnotherRoute" />
</when>
<otherwise>
<throwException ref="redeliveryException" />
</otherwise>
</choice>
</route>
bean中的声明:
<bean id="noErrorHandler" class="org.apache.camel.builder.NoErrorHandlerBuilder"/>
谢谢你的解释。我将发布正确答案:
<route id="sampleRoute">
<from uri="direct:anotheRoute" />
<to uri="direct:kaboom" />
<onException>
<exception>java.net.SocketException</exception>
<exception>java.net.ConnectException</exception>
<exception>my.custom.error.RedeliveryException</exception>
<redeliveryPolicy ref="customRedeliveryPolicy" />
</onException>
</route>
<route errorHandlerRef="noErrorHandler">
<from uri="direct:kaboom />
<to uri="nmr:kaboom/>
<choice>
<when>
<xpath>//result = 'true'</xpath>
<to uri="direct:anotherAnotherRoute" />
</when>
<otherwise>
<throwException ref="redeliveryException" />
</otherwise>
</choice>
</route>
bean中的声明:
<bean id="noErrorHandler" class="org.apache.camel.builder.NoErrorHandlerBuilder"/>