当抛出自定义异常时,是否有可能绕过直接通道中的故障转移策略?
如果我添加自定义错误通道 - 在所有订阅者都耗尽后,错误消息将到达错误通道(在我的情况下,所有 JmsOutboundGateway 将失败)。
在我的例子中,我想检查 inputLocalChannel 中的第一个错误是什么(在我的例子中是 jmsOutboundGateway),如果是预期的错误,则停止处理(故障转移流程 - 不要将其传递给其他订阅者)并抛出错误- 将其传递给回调 -> 出错时
@MessagingGateway(name = "LocalGateway")
public interface LocalGateway {
@Gateway(requestChannel = "inputLocalChannel")
ListenableFuture<Message<String>> sendMsg(Message<String> request);
}
@Bean
@ServiceActivator(inputChannel = "inputLocalChannel")
public Message<String>firstHandler(){
// some code
}
@Bean
@ServiceActivator(inputChannel = "inputLocalChannel")
public Message<String> secondHandler(){
// some code
}
@Bean
@ServiceActivator(inputChannel = "inputGateway")
public JmsOutboundGateway firstGateway(){
// some code
}
@Bean
@ServiceActivator(inputChannel = "inputGatewayBck")
public JmsOutboundGateway secondGateway(){
// some code
}
看起来您想要一些可以称为“条件故障转移”的东西。
该功能确实不适用于
DirectChannel
,而且我不认为它必须如此。
我建议您查看
ErrorMessageExceptionTypeRouter
:https://docs.spring.io/spring-integration/reference/router/implementations.html#router-implementations-exception-router。这样您就需要有更多频道,包括 errorChannel
的 @MessagingGateway
选项。因此,当第一个网关发生错误时,您可以通过该ErrorMessageExceptionTypeRouter
来处理它并决定下一步该去哪里。