简体   繁体   English

Spring集成流异步中的错误处理

[英]Error handling in Spring integration flow async

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. 我有以下Spring Integration配置,它允许我从MVC Controller调用一个网关方法并让控制器返回,而集成流将在一个不阻塞控制器的单独线程中自行继续。

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. 相反,我看到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);

}

What should I do in order to see my exceptions happening in the async integration flow being handled by my error handler? 我应该怎么做才能看到我的错误处理程序正在处理异步集成流程中发生的异常?

A gateway with a void return expects no reply so there is no reply/error channel added to the message headers. 具有void返回的网关不期望回复,因此没有向消息头添加回复/错误通道。 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. 对于这种情况,您需要添加标头errorChannel以将errorChannel标头设置为错误通道。

We should look into doing that automatically, but it does not happen currently. 我们应该自动调查,但目前不会发生。

I opened a JIRA Issue for this. 我为此开了一个JIRA问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM