سؤال

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top