...
To use a Python expression use the following Java code
Code Block |
---|
|
import static org.apache.camel.builder.script.ScriptBuilder.*;
...
... python("somePythonExpression") ...
|
For example you could use the python function to create an Predicate in a Message Filter or as an Expression for a Recipient ListSince you can't get the python expression script evaluation result from the script engine, you need to add a prefix " result = " before your expression.
We will take the result variable as the expression result.
Example
In the sample below we use Python to create a Predicate use in the route path, to route exchanges from admin users to a special queue.
Code Block |
---|
|
from("direct:start")
.choice()
.when().python("request.headers['user'] == 'admin'").to("seda:adminQueue")
.otherwise()
.to("seda:regularQueue");
|
And a Spring DSL sample as well:
Code Block |
---|
|
<route>
<from uri="direct:start"/>
<choice>
<when>
<python>request.headers['user'] == 'admin'</python>
<to uri="seda:adminQueue"/>
</when>
<otherwise>
<to uri="seda:regularQueue"/>
</otherwise>
</choice>
</route>
|
Include Page |
---|
| Scripting Languages Context |
---|
| Scripting Languages Context |
---|
|