看起来您想获得failover pattern。为此,您可以简单地将两个端点订阅到同一个频道,但没有load-balancing:
<channel id="input">
<dispatcher load-balancer="none"/>
</channel>
<service-activator input-channel="input" ref="service1"/>
<service-activator input-channel="input" ref="service2"/>
在这种情况下,如果第一个 <service-activator> 由于某种原因失败,消息将被传递到第二个。
并且没有理由使用retry,或者尝试从错误处理中重新建立流程。
更新:
要跳过一些异常并故障转移到下一个订阅者,您可以使用一些自定义 RequestHandlerAdvice(Expression Evaluating Advice):
class ExceptionProviderRequestHandlerAdvice extends ExpressionEvaluatingRequestHandlerAdvice {
@Override
protected Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) throws Exception {
def result = super.doInvoke(callback, target, message)
if (result in Exception) {
throw result
}
return result
}
}
您的onFailureExpression 应该决定:是否返回异常以重新抛出:
<int:request-handler-advice-chain>
<beans:bean class="com.cs.otppr.core.aop.ExceptionProviderRequestHandlerAdvice">
<beans:property name="returnFailureExpressionResult" value="true"/>
<beans:property name="onFailureExpression"
value="#exception instanceof T (com.my.proj.MyException) ? #exception : null"/>
</beans:bean>
</int:request-handler-advice-chain>
或者,当然,您可以尝试自己寻找解决方案...