Class component
The
classcomponent calls a bean by name, like bean; in Cameleer the "class name" is looked up in the registry.
Scheme: class: · Crate: cameleer-core · Cargo feature: none, always included (build features) ·
Consumer: no · Producer: yes · Apache Camel: Class
When to use it
- Keep Camel routes that use
class:com.example.Greeterworking: bind a Rust bean under that name. - Any case where bean fits; the two schemes behave the same.
Difference from Apache Camel: Camel creates a new instance of a Java class. Rust has no runtime class
loading, so Cameleer resolves the name in the registry, exactly like bean:.
URI format
class:name[?method=methodName]Example
- route:
id: greet
from:
uri: direct:greet
steps:
- to: class:com.example.Greeter?method=greetRegister the bean under the class name:
use cameleer_core::component::bean::{bind_bean, BeanMethods};
use cameleer_core::prelude::*;
pub fn register(ctx: &CamelContext) {
let greeter = BeanMethods::new().method_value("greet", |ex: &Exchange| Ok(Value::from(format!("Hello {}", ex.body()))));
bind_bean(ctx.registry(), "com.example.Greeter", greeter);
}Sending Ada returns Hello Ada.
Rust DSL
use cameleer_core::prelude::*;
pub fn routes(ctx: &CamelContext) -> Result<()> {
ctx.add_routes(|b| {
b.from("direct:greet").route_id("greet").to("class:com.example.Greeter?method=greet");
})
}Options
The same as bean: method; scope, cache, parameters.* and bean.* are accepted
and ignored.
Message headers
| header | direction | description |
|---|---|---|
CamelBeanMethodName | in | Overrides the method option. |
Run it with Docker
Like bean, the bean must be registered by a Rust program, so the stock image cannot run this route on its own.
Common questions
Does class: create a new object per call?
No. It calls the object bound in the registry under that name.
Related
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.