MuleESB / Apache Camel Interview Questions
How does the Enrich EIP (Content Enricher) work in Camel (enrich vs pollEnrich)?
The Content Enricher augments a message with data fetched from an external resource. Camel provides two variants:
- enrich(uri): Calls the external resource using a producer (e.g., HTTP GET, SQL query) and merges the response into the original message using an AggregationStrategy. The original Exchange is enriched in-place.
- pollEnrich(uri): Polls a consumer endpoint (e.g., file: or jms:) to fetch a resource and merges it. Useful for fetching reference data from a file or a JMS queue.
// enrich: HTTP GET to add product details to an order:
from("jms:queue:orders")
.enrich("http://product-service/api/products",
new AggregationStrategy() {
public Exchange aggregate(Exchange orig, Exchange resource) {
String product = resource.getIn().getBody(String.class);
orig.getIn().setHeader("productDetails", product);
return orig;
}
})
.to("direct:process");
// pollEnrich: fetch the latest reference file:
from("direct:start")
.pollEnrich("file:/data/config?fileName=rates.csv", 3000,
new FileBodyMergeStrategy())
.to("direct:applyRates");The key difference: enrich() PUSHES to the resource endpoint (producer call, needs active request); pollEnrich() PULLS from the resource endpoint (consumer poll). If pollEnrich() times out before finding data (timeout in ms, or -1 to wait indefinitely), it returns the original Exchange unchanged.
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...
