Spring集成流异步中的错误处理
我有以下Spring Integration配置,它允许我从MVC Controller调用一个网关方法并让控制器返回,而集成流将在一个不阻塞控制器的单独线程中自行继续。
I have the following Spring Integration configuration that allows me to call a gateway method from MVC Controller and letting controller return, while integration flow will continue on its own in a separate thread that does not block controller.
但是,我无法弄清楚如何使我的错误处理程序适用于此异步流程。我的网关定义了错误通道,但由于某些原因我的异常没有达到它。相反,我看到 LoggingHandler
被调用。
However, I cannot figure out how to get my error handler to work for this async flow. My gateway has error channel defined, but my exceptions do not reach it for some reason. Instead, I see that LoggingHandler
gets invoked.
@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();
}
网关:
@MessagingGateway(errorChannel = "interactiveExceptionChannel")
public interface InteractiveSlackGW {
@Gateway(requestChannel = "input")
void interactiveMessage(Collection<Request> messages);
}
我应该怎么做才能看到我发生的例外情况异步集成流由我的错误处理程序处理?
What should I do in order to see my exceptions happening in the async integration flow being handled by my error handler?
具有 void $的网关c $ c> return预计没有回复,因此没有回复/错误通道添加到邮件头。在调用线程上运行时,会向调用者抛出异常;对于异步流,异常将转到默认的
errorChannel
(附加了日志适配器)。
A gateway with a void
return expects no reply so there is no reply/error channel added to the message headers. When run on the calling thread, the exception is thrown to the caller; with an async flow, the exception will go to the default errorChannel
(which has a log adapter attached).
对于这种情况,您需要添加标头扩充器以将 errorChannel
标头设置到您的错误通道。
For this scenario, you need to add a header enricher to set the errorChannel
header to your error channel.
我们应该自动调查,但目前不会发生。
We should look into doing that automatically, but it does not happen currently.
我打开了一个 JIRA问题。