骡子3.7直到成功失败表达不起作用

时间:2016-07-23 09:56:43

标签: web-services http mule

我正在使用,直到成功重新调用Web服务才会失败 以下是我的尝试:

<until-successful maxRetries="10" failureExpression="#[(message.inboundProperties['http.status'] != 200) &amp;&amp; (message.inboundProperties['http.status'] != 500)]" synchronous="true" millisBetweenRetries="5000">

<flow-ref name="callSubFlow" doc:name="Flow Reference"/>

如果我收到HTTP响应500,我也不想重试调用Web服务。我已经模拟了一个Web服务,当它返回HTTP 500响应时,直到成功继续重试调用Web服务。上面的failureExpression出了什么问题?

由于

3 个答案:

答案 0 :(得分:2)

围绕这个表达存在很多混淆。根据文件,

FAILURE:“直到成功范围内的消息处理器抛出异常或包含异常有效负载。此外,如果在属性failureExpression中提供了一个表达式,它的计算结果为true。”

https://docs.mulesoft.com/mule-user-guide/v/3.6/until-successful-scope#success-and-failure

这里的问题是,当前实现的Mule'failureExpression'被检查并在没有抛出异常时使用 。否则,它总是在异常的情况下重试。您的问题的解决方案是为特定异常设置一个catch块然后设置一个属性,在failureExpression中评估该属性以重试直到成功为止。基本上,您将使用递归技术类代码进行重试。

代码示例:

<until-successful maxRetries="10" failureExpression="#[flowVars['errorInActualOutboundFlow']]" synchronous="true" millisBetweenRetries="5000">
   <flow-ref name="callActualOutboundFlow" doc:name="Flow Reference"/>
</until-successful>

实际出站流程:

 <flow name="callActualOutboundFlow" processingStrategy="synchronous">        
    <http:request config-ref="HTTP_Request_Configuration" path="/" method="GET" doc:name="HTTP"/>
    <choice-exception-strategy doc:name="Choice Exception Strategy"> 
        <catch-exception-strategy doc:name="Catch Exception Strategy" when="#[exception.causedBy(java.net.ConnectException)]">
           <logger message="#### Until-Successful will retry in this case " level="INFO" doc:name="Logger"/>
           <set-variable variableName="errorInActualOutboundFlow" value="#[true]" doc:name="Variable"/>
        </catch-exception-strategy>
        <catch-exception-strategy doc:name="Catch Exception Strategy">
            <set-variable variableName="errorInActualOutboundFlow" value="#[false]" doc:name="Copy_of_Variable"/>

                          

答案 1 :(得分:1)

以下是修复问题的方法。我创建了另一个只捕获Web Service 500错误的流程。直到-successful然后不再重试再次调用Web服务。

<until-successful maxRetries="${webservice.timeout.max.retries}" failureExpression="#[exception != null &amp;&amp; (exception.causedBy(java.net.ConnectException) || exception.causedBy(java.net.SocketTimeoutException) || exception.causedBy(java.util.concurrent.TimeoutException) || exception.causedBy(java.net.SocketException))]" 
synchronous="true" millisBetweenRetries="5000" >
 <processor-chain doc:name="Processor Chain">


      <set-payload value="#[payLoad]" />
      <flow-ref name="Flow1" />

  </processor-chain>
</until-successful>

<flow name="Flow1">
<ws:consumer config-ref="WSConsumerConfig" operation="execute"  />
    <choice-exception-strategy doc:name="Choice Exception Strategy">


      <catch-exception-strategy doc:name="Catch Exception Strategy" when="#[exception != null &amp;&amp; exception.causedBy(org.mule.module.ws.consumer.SoapFaultException)]">

        <logger message="SoapFaultException occurred." level="INFO" doc:name="Logger"/>
        <set-payload value="#[exception]" doc:name="Set Payload"></set-payload>
     </catch-exception-strategy>

    </choice-exception-strategy>
</flow>

答案 2 :(得分:0)

在这种情况下,您还需要告诉HTTP Request组件500是非故障情形。因为默认情况下200是成功方案,除了在成功状态代码验证器中需要提及的任何内容之外。

<until-successful maxRetries="5" synchronous="true" doc:name="Until Successful" failureExpression="#[  message.inboundProperties['http.status'] != 200  &amp;&amp; message.inboundProperties['http.status'] != 500     ]" millisBetweenRetries="1000">
        <http:request config-ref="HTTP_Request_Configuration" path="test1" method="GET" doc:name="HTTP">
            <http:success-status-code-validator values="200,500"/>. 
        </http:request>
</until-successful>

而不是在这里直接使用HTTP,相信您在callSubFlow使用了HTTP请求,在<http:success-status-code-validator values="200,500"/>中提及成功。所以它在这种情况下不会重试,按预期工作。 如果您想将500作为200以外的单独逻辑处理,您可以在http:request之后通过检查其message.inboundProperties [&#39; http.status&#39;]进行条件检查,然后继续逻辑基于200500

在你的情况下失败了,因为Http-request说&#39; 500&#39;作为失败,直到被提及为非失败。