How to carry over header info to errorChannel?

拜拜、爱过 提交于 2019-12-21 17:48:53

问题


In my application, my gateway is receiving request identifier in header, whenever error happens, error channel receives the exception. But it seems like, errorChannel don't take the headers from gateway.

Is it possible to carry over the header information to error channel as well?

Sample example: sysout in sampleErrorChannel does not has the header which i have passed.

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


回答1:


The message on the error channel is an ErrorMessage, it has a payload of MessagingException which has two properties, the cause (exception) and failedMessage.

You can access the failed message headers that way.

e.g. payload.failedMessage.headers['foo'] when using SpEL.

If using a POJO service activator on the error flow, you can use

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


来源:https://stackoverflow.com/questions/31778650/how-to-carry-over-header-info-to-errorchannel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!