Headerenricher Spring Integration and java dsl

不问归期 提交于 2019-12-10 20:52:00

问题


I'me using Spring Integration and java dsl specifications to implement my IntegrationFlow. I want to use an custom header enricher to add some file names to the header, it will be something like :

public class FileHeaderNamingEnricher {
    public Message<File> enrichHeader(Message<File> fileMessage) {
            // getting some details fom the database ...
            return messageBuilder
                    .setHeader("filename", "somestuff")
                    .build();
        }  
}

And my Integration flow will look like :

public IntegrationFlow myflow() {
        return IntegrationFlows.from("input")
                                .enrich // here I want to enrich the header using my class
    }

Can any one help me with this please ?


回答1:


You can have your FileHeaderNamingEnricher extend AbstractReplyProducingMesageHandler (put your code in handleRequestMessage()).

Or, implement GenericHandler<T> (its handle method gets the payload and headers as parameters and can return a message).

Then use the .handle method...

 ...
 .handle(myEnricher())
 ...

 @Bean
 public void MessageHandler myEnricher() {
    return new FileHeaderNamingEnricher();
 }


来源:https://stackoverflow.com/questions/27314651/headerenricher-spring-integration-and-java-dsl

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