MuleESB / Apache Camel Interview Questions
How does the Aggregator EIP work and what is a completion condition?
The Aggregator collects multiple messages that share a common correlation key and merges them into a single output message. It is the inverse of the Splitter and is needed when you receive many individual records (orders, events, sensor readings) that must be batched together before forwarding.
An aggregator requires two things: a correlation expression (how to group messages) and a completion condition (when to emit the aggregated message). Completion can be triggered by:
completionSize(n): emit when n messages are collected.completionTimeout(ms): emit when the oldest message in the group is ms milliseconds old.completionInterval(ms): emit every ms milliseconds regardless of size.completionPredicate(expr): emit when a custom predicate on the aggregated body is satisfied.completionFromBatchConsumer(): use CamelBatchComplete header set by batch-aware consumers like file: and JPA.
from("jms:queue:order-items")
.aggregate(header("orderId"), new GroupedBodyAggregationStrategy())
.completionSize(10)
.completionTimeout(5000)
.to("direct:sendBatch");
// Custom aggregation strategy:
public class ConcatStrategy implements AggregationStrategy {
public Exchange aggregate(Exchange old, Exchange newEx) {
String body = old == null ? ""
: old.getIn().getBody(String.class);
body += newEx.getIn().getBody(String.class) + ",";
newEx.getIn().setBody(body);
return newEx;
}
}
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...
