Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the asciidoc in the repository: https://github.com/apache/camel/blob/master/README.md https://github.com/apache/camel/blob/master/components/readme.adoc
Bean LanguageThe purpose of the Bean Language is to be able to implement an Expression or Predicate using a simple method on a bean. The bean name is resolved using a Registry, such as the Spring The Bean Binding rules are used to bind the Message Exchange to the method parameters; so you can annotate the bean to extract headers or other expressions such as XPath or XQuery from the message. Using Bean Expressions in Javafrom("activemq:topic:OrdersTopic")
.filter().method("myBean", "isGoldCustomer")
.to("activemq:BigSpendersQueue");
Using Bean Expressions in Spring XML<route>
<from uri="activemq:topic:OrdersTopic"/>
<filter>
<method ref="myBean" method="isGoldCustomer"/>
<to uri="activemq:BigSpendersQueue"/>
</filter>
</route>
Bean Attribute Now Deprecated The Writing the Expression BeanThe bean in the above examples is just any old Java Bean with a method called Example: public class MyBean {
public boolean isGoldCustomer(Exchange exchange) {
// ...
}
}
We can also use the Bean Integration annotations. Example: public boolean isGoldCustomer(String body) {...}
or public boolean isGoldCustomer(@Header(name = "foo") Integer fooHeader) {...}
So you can bind parameters of the method to the Exchange, the Message or individual headers, properties, the body or other expressions. Non-Registry BeansThe Bean Language also supports invoking beans that isn't registered in the Registry. This is usable for quickly to invoke a bean from Java DSL where you don't need to register the bean in the Registry such as the Spring Example: from("activemq:topic:OrdersTopic")
.filter().expression(BeanLanguage(MyBean.class, "isGoldCustomer"))
.to("activemq:BigSpendersQueue");
The 2nd parameter private MyBean my;
from("activemq:topic:OrdersTopic")
.filter().expression(BeanLanguage.bean(my, "isGoldCustomer"))
.to("activemq:BigSpendersQueue");
In Camel 2.2: you can avoid the private MyBean my;
from("activemq:topic:OrdersTopic")
.filter().expression(bean(my, "isGoldCustomer"))
.to("activemq:BigSpendersQueue");
Which also can be done in a bit shorter and nice way: private MyBean my;
from("activemq:topic:OrdersTopic")
.filter().method(my, "isGoldCustomer")
.to("activemq:BigSpendersQueue");
Other ExamplesWe have some test cases you can look at if it'll help
DependenciesThe Bean language is part of |
