2017-09-19 21 views
2

私は時々503エラーを返すhttpゲートウェイ呼び出しを持っています。私はその呼び出しの周りにretry adviceを設定したいと思いますが、私は503だけのすべてのエラーに対してそれをしたくありません。Spring統合メッセージフローの条件付き再試行アドバイス?

<int-http:outbound-gateway ... errorHandler="..."> 
    <int-http:request-handler-advice-chain> 
     <int:retry-advice max-attempts="3" /> 
    </int-http:request-handler-advice-chain> 
</int-http:outbound-gateway> 

私はすでにカスタムエラーハンドラがステータス(例:404)をフィルタリングその設定されている、私はエラーとして扱いする必要はありませんが、私はアドバイスが適用される方法を制御するために明白な方法が表示されません私がエラーハンドラでできることに基づいています。 This questionは同じ問題を扱いますが、答えにはアドバイスの動作を制御する方法や、エラーハンドラレベルで要求を再発行する方法は説明されていません。スローする特定の例外タイプはありますか?

編集:答えに基づい例:

<bean id="spelParser" class="org.springframework.expression.spel.standard.SpelExpressionParser" /> 

<int-http:outbound-gateway ...> 
    <int-http:request-handler-advice-chain> 
     <bean class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice"> 
      <property name="retryTemplate"> 
       <bean class="org.springframework.retry.support.RetryTemplate"> 
        <property name="retryPolicy"> 
         <bean class="org.springframework.retry.policy.ExpressionRetryPolicy"> 
          <constructor-arg index="0" type="org.springframework.expression.Expression" value="#{spelParser.parseExpression('cause.statusCode.value() == 503')}" /> 
          <property name="maxAttempts" value="3" /> 
         </bean> 
        </property> 
        <property name="backOffPolicy"> 
         <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy"> 
          <property name="initialInterval" value="1000" /> 
          <property name="multiplier" value="2" /> 
         </bean> 
        </property> 
       </bean> 
      </property> 
     </bean> 
    </int-http:request-handler-advice-chain> 
</int-http:outbound-gateway> 

答えて

0

さて、あなたはHttpServerErrorExceptionを持っていますが、他の人からstatusCodeによってそれを区別したいと思いますし、再試行していないときの場合のために、私が取ることをお勧め

あなたの式はのようにすることができ
* Subclass of {@link SimpleRetryPolicy} that delegates to super.canRetry() and, 
* if true, further evaluates an expression against the last thrown exception. 
* 
* @author Gary Russell 
* @since 1.2 
* 
*/ 
@SuppressWarnings("serial") 
public class ExpressionRetryPolicy extends SimpleRetryPolicy implements BeanFactoryAware { 

expression="statusCode.value() == 503" 
に見て

更新

Ah!そうですか。 ExpressionRetryPolicyTemplateParserContextを使用しているので、あなたの式は間違いなく#{statusCode.value() == 503}のようになります。しかし同時に、Beanファクトリーの初期化時に評価されることになります。

<bean id="spelParser" class="org.springframework.expression.spel.standard.SpelExpressionParser"/> 

ExpressionRetryPolicy Bean定義で行います:

<constructor-arg index="0" type="org.springframework.expression.Expression" 
       value="#{spelParser.parseExpression('statusCode.value() == 503')}" /> 

を衝突を克服するために、私はあなたがこのような何かを示唆しています。

+0

ポリシーをカスタマイズするには、カスタムポリシーでカスタム 'RetryTemplate'を注入して、' '(' RequestHandlerRetryAdvice')としてアドバイスを提供します。 –

+0

私はExpressionRetryPolicyをワイヤリングする方法を見ていると思います。 (私はその依存関係を別々に取得する必要がありました。なぜなら、春の統合:4.3.12.RELEASEは、そのクラスが導入された新しいバージョン1.2ではなく、Springリトライ:1.1.xのみを取得します)。しかし、これは式を解決できないためです。 ( 'EL1008E: 'org.springframework.beans.factory.config.BeanExpressionContext'の型のオブジェクトで '$ statusCode'というプロパティまたはフィールドが見つかりませんでした。おそらくpublicではないでしょうか?)私が試みたSPELは' expression = "#{$ statusCode.value()== 503} "' –

+0

???それはSpELではありません。ランタイム表現を指定する必要があります。そして私はすでにあなたに言った: 'expression =" statusCode.value()== 503 "'。あなたがしようとしているのは、 'bean factory initialization expression'と呼ばれますが、実際には実行時ではありません。とにかく '$'シンボルも間違っています... –

関連する問題