【问题标题】:Enriching Header with the value from the Transformer使用 Transformer 中的值丰富 Header
【发布时间】:2019-04-20 23:21:44
【问题描述】:

我有一个spring integration flow. 它读取文件。该文件可以属于消费者。一旦我找到消费者,我想将 CONSUMER 添加到标题中,以便稍后我可以使用例如在错误处理中,我可以检查我是否得到了consumer 查看标题。

IntegrationsFlows.from(directorySource)
.transform(new ConsumerFinderTransformer()
.enrichHeaders(h -> h.header("CONSUMER" ,payload)

如何获取enrichHeaders 中由ConsumerFinderTransformer 返回的有效负载。

我找不到办法。任何帮助将不胜感激

【问题讨论】:

    标签: java-8 spring-integration spring-integration-dsl


    【解决方案1】:

    这个是为你准备的:

        /**
     * Add a single header specification where the value is a String representation of a
     * SpEL {@link Expression}. If the header exists, it will <b>not</b> be overwritten
     * unless {@link #defaultOverwrite(boolean)} is true.
     * @param name the header name.
     * @param expression the expression.
     * @return the header enricher spec.
     */
    public HeaderEnricherSpec headerExpression(String name, String expression) {
    

    所以,你的代码应该是这样的:

    .enrichHeaders(h -> h.headerExpression(“CONSUMER" , “payload”)
    

    【讨论】:

    • 很高兴我们有你在 SO :) 谢谢@Artem
    • 但是普通的API(无表达式)也应该有这个方法
    • 还有一个headerFunction()作为变体
    猜你喜欢
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    • 2011-07-27
    • 2014-05-23
    • 2023-04-08
    • 2011-08-29
    • 2010-12-30
    相关资源
    最近更新 更多