MuleESB / Apache Camel Interview Questions
How does the Content-Based Router EIP work in Camel (choice/when/otherwise)?
The Content-Based Router (CBR) routes each incoming message to exactly one destination based on its content. In Camel it is implemented with choice() — when(predicate) — otherwise() — end(). Only the first matching when() branch executes; otherwise() catches messages that match no predicate.
from("direct:orders")
.choice()
.when(header("region").isEqualTo("EU"))
.to("jms:queue:eu-orders")
.when(header("region").isEqualTo("US"))
.to("jms:queue:us-orders")
.when(simple("${header.priority} == HIGH"))
.to("jms:queue:priority-orders")
.otherwise()
.to("jms:queue:default-orders")
.end();Predicates can use Simple, XPath, JSONPath, SpEL, or custom expressions. After .end() the route continues the normal flow. To continue processing AFTER every branch (not just the matching one), use endChoice() and add further steps. The when() predicate has access to the full Exchange including headers, body, and properties.
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...
