camel-language-simple
Simple Language interpreter for rust-camel YAML DSL
Overview
camel-language-simple implements Apache Camel's Simple Language — a lightweight expression language for accessing exchange data and building predicates in route definitions.
Supported Expressions
| Syntax | Description |
|---|---|
${header.name} |
Access a message header by name |
${body} |
Access the message body as text |
${body.field} |
Access JSON body field (dot-notation) |
${body.nested.field} |
Access nested JSON fields |
${body.array.0} |
Access array element by index |
${exchangeProperty.name} |
Access an exchange property |
true / false |
Boolean literals |
null |
Null literal |
Note: Body field access (
${body.field}) only works onBody::Jsonand returnsValue::Nullfor other body types or missing fields.
Supported Operators
| Operator | Example | Description |
|---|---|---|
== |
${header.type} == 'order' |
Equality |
!= |
${header.type} != null |
Inequality |
> |
${header.age} > 18 |
Greater than (numeric) |
< |
${header.age} < 100 |
Less than (numeric) |
>= |
${header.count} >= 5 |
Greater than or equal |
<= |
${header.count} <= 10 |
Less than or equal |
contains |
${body} contains 'hello' |
String contains |
&& |
${header.type} == 'order' && ${header.priority} == 'high' |
Logical AND (short-circuit) |
|| |
${header.type} == 'order' || ${header.type} == 'invoice' |
Logical OR (short-circuit) |
Compound Predicates
Combine multiple conditions with && (AND) and || (OR):
| Expression | Description |
|---|---|
${body} != null && ${body} != '' |
Body is present and non-empty |
${header.type} == 'order' || ${header.type} == 'invoice' |
Type is order or invoice |
${body.status} == 'active' && ${body.score} > 50 |
Status is active AND score > 50 |
Precedence: && binds tighter than ||. ${a} \|\| ${b} && ${c} is parsed as ${a} \|\| (${b} && ${c}).
Null Semantics
| Expression | Result | Notes |
|---|---|---|
${body} with empty exchange |
Value::Null |
Empty body is null, not empty string |
${header.missing} |
Value::Null |
Missing headers return null |
${body} != null |
false when body is empty, true when body has content | Use to check if body exists |
null > 5 |
false | Null is not comparable for ordering |
null == null |
true | Null equals null |
null contains 'x' |
false | Null is not searchable |
Boolean Comparisons
Compare JSON boolean fields with true/false literals:
- filter:
language: simple
source: "${body.active} == true"
Usage
use SimpleLanguage;
use Language;
let lang = SimpleLanguage;
// Create a predicate
let pred = lang.create_predicate.unwrap;
// Create an expression
let expr = lang.create_expression.unwrap;
Registration
SimpleLanguage is registered by default in CamelContext under the name "simple":
let ctx = new;
let lang = ctx.resolve_language.unwrap;
License
Apache-2.0