Apache Camel 在另一个故障转移执行轮循机制之前捕获故障转移尝试



>我正在使用具有以下路由配置的 apache 驼峰故障转移组件:

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

我想在引发连接异常时发出电子邮件。但是,在我的示例中,与发送电子邮件关联的进程仅在最大故障转移尝试耗尽后引发连接异常后调用。我想在故障转移轮循机制并选择下一个 uri 之前为每个连接异常发送电子邮件。

这在骆驼 2.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> 

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

这无法使用故障转移负载均衡器。不能对引发的异常执行自定义处理。

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

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

最新更新