1

分離器之後,處理消息時發生異常。我想要處理這個異常,並將一條新消息引導至公共通道,並在消息的相關標識中產生異常,並提供一個指明錯誤的特殊標頭。如何引導在異常流程中保存當前關聯標識的新消息

我試着這樣說:

@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在郵件標題中。

有誰知道我做錯了嗎?提前致謝。

回答

1

到達錯誤通道的消息是ErrorMessage。其​​是(通常)MessagingException。那個,反過來,有failedMessage財產。

你需要的是這樣的:

.<MessagingException>handle((p, h) -> MessageBuilder.fromMessage(p.getFailedMessage()).setHeader("ERROR", true).build()) 

你並不需要複製標題,因爲他們是在failedMessage已經存在。 ErrorMessage不關心(也不能)關於標題,因爲它只是處理異常。

相關問題