我有以下 Spring Integration 配置,它允许我从 MVC 控制器调用网关方法并让控制器返回,而集成流将在不阻塞控制器的单独线程中自行继续。
但是,我无法弄清楚如何让我的错误处理程序适用于此异步流程。我的网关定义了错误通道,但由于某种原因我的异常没有到达它。相反,我看到LoggingHandler
被调用。
@Bean
IntegrationFlow mainInteractiveFlow() {
return IntegrationFlows.from(
MessageChannels.executor("input", executor))
.split()
.channel(MessageChannels.executor(executor))
.transform(transformer)
.handle(genericMessageHandler, "validate")
.handle(genericMessageHandler, "checkSubscription")
.handle(interactiveMessageService, "handle")
.<Task, String>route(p -> p.getKind().name(),
m -> m.channelMapping(TaskKind.ABC.name(), "attachInteractiveChannel"))
.get();
}
@Bean
IntegrationFlow attachInteractiveChannelFlow() {
return IntegrationFlows.from(
MessageChannels.direct("attachInteractiveChannel"))
.handle(issueRouterService)
.get();
}
@Bean
IntegrationFlow interactiveExceptionChannelFlow() {
return IntegrationFlows.from(interactiveExceptionChannel())
.handle(errorHandler, "handleErrorMessage")
.get();
}
@Bean
MessageChannel interactiveExceptionChannel() {
return MessageChannels.direct("interactiveExceptionChannel").get();
}
Gateway:
@MessagingGateway(errorChannel = "interactiveExceptionChannel")
public interface InteractiveSlackGW {
@Gateway(requestChannel = "input")
void interactiveMessage(Collection<Request> messages);
}
我应该做什么才能看到错误处理程序处理的异步集成流中发生的异常?
网关带有void
return 预计不会有回复,因此消息标头中不会添加回复/错误通道。当在调用线程上运行时,异常被抛出给调用者;对于异步流,异常将转到默认值errorChannel
(附有日志适配器)。
对于这种情况,您需要添加标头丰富器来设置errorChannel
标头到您的错误通道。
我们应该考虑自动执行此操作,但目前还没有发生。
我开了一个JIRA 问题为了这。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)