MuleESB / Apache Camel Interview Questions
How does the Camel Bean component work — binding method calls into a route?
The Bean component invokes a method on a Spring/CDI/JNDI bean from within a route. It is the recommended way to call business logic without tying domain classes to the Camel API: the bean knows nothing about Camel — it just receives parameters and returns a value.
// Bean referenced by class:
from("jms:queue:orders")
.bean(OrderService.class, "processOrder")
.to("jms:queue:results");
// Bean by Spring bean name:
from("direct:validate")
.bean("orderService", "validate(Exchange)")
.log("Validated: ${body}");
// Parameter binding annotations in the bean class:
public class OrderService {
public Order processOrder(
@Body String rawJson,
@Header("orderId") String id,
@ExchangeProperty("tenantId") String tenant) {
return orderRepo.save(parse(rawJson, id, tenant));
}
}Camel uses reflection and the Bean Parameter Binding mechanism to automatically map Exchange data to method parameters: @Body injects the message body, @Header(name) injects a header, @ExchangeProperty(name) injects a property. If there are no annotations, Camel uses the body type to match. The return value of the method becomes the new message body.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
