camel-language-rhai
Rhai scripting language for rust-camel
Overview
camel-language-rhai provides a Rhai scripting language integration for rust-camel, similar to Apache Camel's Groovy or JavaScript language support. Rhai is an embedded scripting language for Rust with no external dependencies.
Available Variables
Scripts have access to these variables injected from the Exchange:
| Variable | Type | Description |
|---|---|---|
body |
String | Message body as text |
headers |
Map | Message headers as a key-value map |
Available Functions
| Function | Description |
|---|---|
header("name") |
Look up a header value by name |
set_header("key", value) |
Set a header; visible within the same script evaluation but not propagated back to the Exchange |
property("name") |
Look up an exchange property by name |
set_property("key", value) |
Set a property; visible within the same script evaluation but not propagated back to the Exchange |
Note:
set_headerandset_propertyallow scripts to pass values between statements within a single evaluation (e.g. set a header then read it back later in the same script). Changes do not persist after the script completes because expressions receive a read-only&Exchangereference.
Usage
use RhaiLanguage;
use Language;
let lang = new;
// Predicate using header lookup
let pred = lang.create_predicate.unwrap;
// Expression with string concatenation
let expr = lang.create_expression.unwrap;
// Full Rhai scripting
let expr = lang.create_expression.unwrap;
Registration
Register manually in CamelContext (not included by default to avoid the Rhai dependency):
use RhaiLanguage;
let mut ctx = new;
ctx.register_language.unwrap;
License
Apache-2.0