Variable language
The
variablelanguage returns the value of one exchange variable (set withsetVariable), or null when it is not set.
Name: variable · Crate: cameleer-core · Cargo feature: none, always included (build features) · Apache Camel: Variable
When to use it
- Store intermediate results under a name (Camel 4 variables) without adding headers that would be sent to the next endpoint.
- Keep the pieces of a multi-step agent flow apart: the user question, the retrieved context, the model answer.
Syntax
The expression text is the variable name. In Simple the same value is
${variable.name}, and ${variables} returns all of them. Variables are stored per exchange.
Examples
- route:
id: variable-demo
from:
uri: direct:variable
steps:
- setVariable:
name: question
simple: "${body}"
- setVariable:
name: context
constant: "Orders ship within 2 days."
- setBody:
simple: "Context: ${variable.context}\nQuestion: ${variable.question}"
- setHeader:
name: asked
variable: questionWhen will my order ship?Context: Orders ship within 2 days.
Question: When will my order ship?{"body": "x", "variables": {"question": "When?", "score": 0.82}}| expression | result |
|---|---|
question | When? |
score | 0.82 |
missing | (empty) |
Options
The variable language has no options. It reads exchange variables only: Apache Camel's
global: and route: prefixes are not interpreted by this language.
Rust DSL
b.from("direct:variable-rust")
.set_body(language("variable", "question"));Common questions
How do I set a variable in YAML?
Use the setVariable step with name and an expression, for example
setVariable: {name: question, simple: "${body}"}.
Are variables sent to endpoints?
No. Unlike headers, variables stay inside the exchange.
Related
- Simple language (
${variable.name},${variables}) - Header language, exchangeProperty language
- Apache Camel Variable language
Found a problem?
If something on this page doesn't match what Cameleer does, or you hit a bug while building
with it, please help fix it, whether you are a person or a coding agent:
open an issue that describes what you saw,
then fork the repository, fix it, add or update a test, run cargo test --workspace, and open
a pull request. CONTRIBUTING.md
explains the ground rules.