Spring 如何引导在异常流中保存当前关联id的新消息

Spring 如何引导在异常流中保存当前关联id的新消息,spring,spring-boot,spring-integration,spring-integration-dsl,Spring,Spring Boot,Spring Integration,Spring Integration Dsl,在拆分器之后,处理消息时会发生异常。我希望处理该异常,并将一条新消息定向到公共通道,该消息具有生成异常的消息的相关id和指示错误的特殊头 我试过这样做: @Bean public IntegrationFlow socialMediaErrorFlow() { return IntegrationFlows.from("socialMediaErrorChannel") .wireTap(sf -> sf.handle("errorService", "ha

在拆分器之后,处理消息时会发生异常。我希望处理该异常,并将一条新消息定向到公共通道,该消息具有生成异常的消息的相关id和指示错误的特殊头

我试过这样做:

@Bean
public IntegrationFlow socialMediaErrorFlow() {
     return IntegrationFlows.from("socialMediaErrorChannel")
           .wireTap(sf -> sf.handle("errorService", "handleException"))
           .handle((p, h) -> MessageBuilder.withPayload(p).copyHeaders(h).setHeader("ERROR", true).build())
           .channel("directChannel_2")
           .get();
}
但聚合器返回此错误:

MessageHandlingException: error occurred in message handler [org.springframework.integration.dsl.AggregatorSpec$InternalAggregatingMessageHandler#0]; nested exception is java.lang.IllegalStateException: Null correlation not allowed.  Maybe the CorrelationStrategy is failing?
我无法复制消息头中的相关id


有人知道我做错了吗?提前感谢。

到达错误频道的消息是
ErrorMessage
。其
有效载荷
通常是
消息异常
。而这一个则具有
failedMessage
属性

你需要的是这样的东西:

.<MessagingException>handle((p, h) -> MessageBuilder.fromMessage(p.getFailedMessage()).setHeader("ERROR", true).build())
.handle((p,h)->MessageBuilder.fromMessage(p.getFailedMessage()).setHeader(“ERROR”,true).build())
您不需要复制标题,因为它们已经存在于
failedMessage
中。
ErrorMessage
不关心(也不能)头,因为它只处理异常