How to access (get) camel header in java dsl

17,482

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.

Share:
17,482

Related videos on Youtube

Rishi
Author by

Rishi

I m a Software Engineer who enjoy the system design, tools & service development in Java & Python, I also spend my time programming small scale web apps in Ruby (Sinatra)... its fun! I've worked in Search, Web Analytic, Experimentation (A/B Testing) domain for last few of years with some great people and now I am working in DevOps domain - Infrastructure Tools & Automation. I m really excited to be a part of Stackoverflow ! Gr8 chance to interact with awesome folks all over the world!! So much to learn !!

Updated on September 16, 2022

Comments

  • Rishi
    Rishi over 1 year

    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?

  • Abhishek Chatterjee
    Abhishek Chatterjee almost 4 years
    What if my header field is a string that is actually a bean-name in Spring context and I want invoke that bean as processor?
  • Gerold Broser
    Gerold Broser over 3 years
    I'm going even further than @AbhishekChatterjee: How to get a reference of a bean object which is assigned to a header to invoke one of its methods?