如何将 header 信息传递给 errorChannel?

How to carry over header info to errorChannel?

在我的应用程序中,我的网关在 header 中接收请求标识符,每当发生错误时,错误通道都会收到异常。但看起来,errorChannel 没有从网关获取 headers。

是否可以将header信息也转移到错误通道?

示例: sampleErrorChannel 中的 sysout 没有我传递的 header。

https://github.com/manojp1988/spring-integration/blob/master/javadsl/src/main/java/ErrorChannel/ErrorChannelExample.java

错误通道上的消息是一个 ErrorMessage,它的负载为 MessagingException,它有两个属性,cause(异常)和 failedMessage

您可以通过这种方式访问​​失败的消息 headers。

例如payload.failedMessage.headers['foo'] 使用 SpEL 时。

如果在错误流上使用 POJO 服务激活器,您可以使用

public void failure(MessagingException failure) {
    MyHeader mh = failure.getFailedMessage().getHeader("mh");
}