简体   繁体   English

Camel…评估Java表达式

[英]Camel…Evaluating a java expression

I have a camel flow which routes from an activemq to another activemq. 我有一个骆驼流,它从一个activemq路由到另一个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? 如何将java.util.UUID.randomUUID().toString()值设置为标头? pls advise 请建议

Use the Groovy expression language for that. 为此使用Groovy表达式语言。 The simple language is ok for concatenating strings and comparing parts of the payload, but for more logic, groovy is a swiss army knife. 简单的语言可以连接字符串并比较部分有效载荷,但是对于更多的逻辑而言,groovy是瑞士军刀。

<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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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