gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:14:07 25 4
gpt4 key购买 nike

我有以下 Spring Integration 配置,允许我从 MVC Controller 调用网关方法并让 Controller 返回,而集成流将在不阻塞 Controller 的单独线程中自行继续。

但是,我不知道如何让我的错误处理程序为这个异步流程工作。我的网关定义了错误 channel ,但由于某种原因我的异常没有到达它。相反,我看到 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 返回值的网关不希望有回复,因此没有回复/错误 channel 添加到消息 header 。在调用线程上运行时,将异常抛给调用者;对于异步流,异常将转到默认的 errorChannel(附加了一个日志适配器)。

对于这种情况,您需要添加 header 丰富器以将 errorChannel header 设置为您的错误 channel 。

我们应该考虑自动执行此操作,但目前还没有发生。

我打开了一个JIRA Issue为此。

关于java - Spring 集成流异步中的错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38911968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com