TSSK
TSSK

Reputation: 209

Apache Camel: Aggregator vs Enrich

I am given to understand both Aggregator and Enrich components combine messages based on an Aggregation Strategy. I don't see much of a difference between the components though. How can i know which one to use?

Upvotes: -1

Views: 838

Answers (1)

Pasi Österman
Pasi Österman

Reputation: 2167

Thinking Aggregator and Enrich as components can be a bit misleading. They're implementations for enterprise integration patterns in camel and as such very integral to how Apache camel works.

For example pipeline pattern and content enricher are things that you're likely already using all the time with Apache camel without even realizing it. With Apache camel you're almost constantly enriching messages using components, translators, beans and processors.

Aggregation Strategy is used to configure how you want camel to combine one or more exchanges. This means it can be used to combine current exchange to a incoming exchange with enrich or to group multiple exchanges in to one when when using split or aggregate.

How can i know which one to use?

They're completely different patterns, one is for enriching exchanges with new data and one grouping exchanges together.

In terms of defining routes with Camel Java-DSL use of .enrich() is pretty uncommon as generally it's enough to call the endpoint directly with to("uri").

More common is .pollEnrich("uri") as with it one can use consumer endpoints like file, ftp or jms to enrich the exchange. Meaning if you need data from two or more files on a route you can use it to do so.

When it comes to .aggregate() it's mainly used to group exchanges together and handle them as a group after some pre-determined condition has been met like for example every 100 exchanges or after 10 seconds of no new exchanges.

Upvotes: 2

Related Questions