Question

I have a camel flow which routes from an activemq to another activemq. However, I need to evaluate an expression and set it as a header. How do I achieve that.

<from uri="jms:queue:Q.activemq1"/>
    <setHeader headerName="EVENT_KEY">
         <simple>${java.util.UUID.randomUUID().toString()}</simple>
    </setHeader>
 <to uri="jms:queue:Q.activemq2"/>

But the header is not being set correctly? How do I set java.util.UUID.randomUUID().toString() value to the header? pls advise

Était-ce utile?

La solution

Use the Groovy expression language for that. The simple language is ok for concatenating strings and comparing parts of the payload, but for more logic, groovy is a swiss army knife.

<from uri="jms:queue:Q.activemq1"/>
    <setHeader headerName="EVENT_KEY">
         <groovy>java.util.UUID.randomUUID().toString()</groovy>
    </setHeader>
 <to uri="jms:queue:Q.activemq2"/>

You need to add a dependency to camel-groovy to make it work.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top