Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access (get) camel header in java dsl

Tags:

apache-camel

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?

like image 648
Rishi Avatar asked Nov 15 '25 17:11

Rishi


1 Answers

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 + "}]")

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

like image 80
Claus Ibsen Avatar answered Nov 17 '25 07:11

Claus Ibsen