Apache camel Apache camel在另一个故障转移执行循环之前捕获故障转移尝试
我正在使用具有以下路由配置的apache camel故障切换组件:Apache camel Apache camel在另一个故障转移执行循环之前捕获故障转移尝试,apache-camel,failover,Apache Camel,Failover,我正在使用具有以下路由配置的apache camel故障切换组件: <route id="jettyRouter" errorHandlerRef="defaultErrorHandler"> <from uri="jetty:http://{{Jetty.entryPoint.host}}?matchOnUriPrefix=true"/> <setExchangePattern pattern="InOut"/> <loadBa
<route id="jettyRouter" errorHandlerRef="defaultErrorHandler">
<from uri="jetty:http://{{Jetty.entryPoint.host}}?matchOnUriPrefix=true"/>
<setExchangePattern pattern="InOut"/>
<loadBalance>
<failover maximumFailoverAttempts="2" roundRobin="true" >
<exception>java.net.ConnectException</exception>
<process ref="customExceptionProcessor" />
</failover>
<to uri="direct:endpointRoute1" />
<to uri="direct:endpointRoute2" />
</loadBalance>
</route>
java.net.ConnectException
我想在出现连接异常时发送电子邮件。然而,在我的示例中,只有在maximumFailoverAttempts耗尽后引发连接异常之后,才会调用与发送电子邮件相关联的进程。我希望在故障切换循环并选择下一个uri之前,为每个连接异常发送电子邮件
这在Camel2.14或2.17.0中可能吗
谢谢,
安贾纳 我不是这个意思,像这样的事情
<route id="jettyRouter" errorHandlerRef="defaultErrorHandler">
<doTry>
<from uri="jetty:http://{{Jetty.entryPoint.host}}?matchOnUriPrefix=true"/>
<doCatch>
<process ref="customExceptionProcessor" /> <!--send mail and rethrow exception from this bean -->
<end>
<setExchangePattern pattern="InOut"/>
<loadBalance>
<failover maximumFailoverAttempts="2" roundRobin="true" >
<exception>java.net.ConnectException</exception>
</failover>
<to uri="direct:endpointRoute1" />
<to uri="direct:endpointRoute2" />
</loadBalance>
</route>
java.net.ConnectException
我没有试过这个。只是一个建议。将其作为答案发布,因为很难将此代码作为注释。任何人都遇到过类似的要求,即在故障转移组件的循环选择另一个端点之前捕获连接异常。这在故障转移负载平衡器中是不可能的。不能对每个引发的异常执行自定义处理
您可以使用常规错误处理程序执行此操作,其中发生了
oneexception
,您可以配置为调用处理器
。但该功能是最近添加的,因此可能不在您正在使用的旧版本的Camel中。您是否尝试将doTry
和doCatch
放在周围,我添加了try-and-catch块,并从我的customExceptionProcess重新抛出连接异常。然而,customexceptionProcess仅在failoverattempts耗尽且所有uri都给出connect异常时才被调用。下面是try-and-catch的配置。java.net.ConnectException为什么不捕获异常并将其发送到错误处理程序路由,而不是让负载平衡器参与其中?我的要求是处理负载平衡器异常。这不会有帮助,因为无法将在路线元素之后多特里。谢谢克劳斯。我的要求是捕获每个连接异常,并在加载故障转移组件之前引发和发送电子邮件。当遇到uri上的连接异常时,请选择另一个uri进行路由。据我所知,此功能在当前的camel版本中也不可用。如果您使用的camel版本中出现了onexceptionoccurrend
,请自行查看。另一种方法是使用onRedelivery
,它在重试之前调用,而不是在抛出异常时100%调用。