Conditional retry advice in a Spring Integration message flow?

风流意气都作罢 提交于 2019-12-02 02:26:31

Well, for the case when you have a HttpServerErrorException but would like to distinguish it by the statusCode from others and don't retry, I would suggest to take a look into the:

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

Where your expression can be like:

expression="statusCode.value() == 503"

UPDATE

Ah! I see. Since ExpressionRetryPolicy uses TemplateParserContext your expression definitely must be like #{statusCode.value() == 503}. But at the same time it is going to be evaluate during bean factory initialization. I suggest you to do something like this:

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

and in the ExpressionRetryPolicy bean definition do:

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

To overcome the collision.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!