Apache camel在另一次故障转移之前捕获故障转移尝试进行循环

时间:2017-11-20 07:54:36

标签: apache-camel failover

我正在使用带有以下路由配置的apache camel故障转移组件:

<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>

我想在引发连接异常时发出电子邮件。但是,只有在maximumFailoverAttempts耗尽后抛出连接异常后,才会调用与我的示例中发送电子邮件相关联的进程。我想在故障转移执行循环之前为每个连接异常发送电子邮件,然后选择下一个uri。

这可能在骆驼2.14或2.17.0吗?

谢谢, 美国之音。

3 个答案:

答案 0 :(得分: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> 

我没试过这个。只是一个建议。将其作为答案发布,因为很难将此代码作为评论。

答案 1 :(得分:0)

故障转移负载均衡器无法做到这一点。您不能对每个抛出的异常进行自定义处理。

您可以使用常规错误处理程序执行此操作,其中有onExceptionOccurred您可以配置为调用Processor。但是最近添加了该功能,因此可能不会出现在您使用的旧版Camel中。

答案 2 :(得分:-1)

在故障转移组件的循环选择另一个端点之前,任何人都遇到了捕获连接异常的类似要求。

相关问题