How to access (get) camel header in java dsl

一个人想着一个人 提交于 2019-12-11 04:08:45

问题


I have a code like -

        // use streaming to increase index throughput
            .setHeader(SolrConstants.OPERATION,
                    constant(SolrConstants.OPERATION_INSERT_STREAMING))
            // define solr endpoint and options
            .to("solr://"
                    + getSolrEndPoint()
                    + "?defaultMaxConnectionsPerHost=500&streamingThreadCount=500&maxRetries=3")
            .log(LoggingLevel.INFO, "Successfully indexed document id [" +header(BatchHeaders.DOCUMENT_ID) +"]")
            // end this route
            .end();

But what I m getting in the log is -

severity="INFO " thread="Camel (camel-1) thread #123 - seda://insert" category="route2" Successfully indexed document id [header{DOC_ID}]

I m not getting the actual header value (the document id).
So my question is - How to access the headers in Java DSL here?


回答1:


The log in the DSL uses the simple language: http://camel.apache.org/simple

So you need to do it like this

.log(LoggingLevel.INFO, "Successfully indexed document id [${header." + BatchHeaders.DOCUMENT_ID + "}]")

eg the ${header.xxx} is evaluated at runtime by the simple language.



来源:https://stackoverflow.com/questions/15111044/how-to-access-get-camel-header-in-java-dsl

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