簡體   English   中英

Spring集成流異步中的錯誤處理

[英]Error handling in Spring integration flow async

我有以下Spring Integration配置,它允許我從MVC Controller調用一個網關方法並讓控制器返回,而集成流將在一個不阻塞控制器的單獨線程中自行繼續。

但是,我無法弄清楚如何使我的錯誤處理程序適用於此異步流。 我的網關定義了錯誤通道,但由於某些原因,我的異常沒有達到它。 相反,我看到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();
}

網關:

@MessagingGateway(errorChannel = "interactiveExceptionChannel")
public interface InteractiveSlackGW {

    @Gateway(requestChannel = "input")
    void interactiveMessage(Collection<Request> messages);

}

我應該怎么做才能看到我的錯誤處理程序正在處理異步集成流程中發生的異常?

具有void返回的網關不期望回復,因此沒有向消息頭添加回復/錯誤通道。 在調用線程上運行時,會向調用者拋出異常; 對於異步流,異常將轉到默認的errorChannel (附加了日志適配器)。

對於這種情況,您需要添加標頭errorChannel以將errorChannel標頭設置為錯誤通道。

我們應該自動調查,但目前不會發生。

我為此開了一個JIRA問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM