简体   繁体   中英

Camel…Evaluating a java expression

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM