Camel - enrichment: enrich () vs pollEnrich ()

1st QUESTION:

I can not understand the difference between enrich() and pollEnrich() . Perhaps the terms Camel are not so great.

I read here: http://camel.apache.org/content-enricher.html

Content Enrichment Using DSL Enrichment

Camel comes with two DSL enriched content flavors

  • enrich
  • pollEnrich

enrich uses Producer to obtain additional data. This is commonly used for Request Reply messaging, for example, to call an external web service. pollEnrich, on the other hand, uses the Consumer Consumer to obtain additional data. It is commonly used to report messaging events, such as reading a file or uploading an FTP file.

I don’t understand what the difference is. They both seem to receive additional data (web service response, FTP file) by consuming it. So why do they say that getting a web service response is done by a "producer"?

2nd QUESTION:

In the book "Camel in Action" p. 72 they say:

Information on the use of enrichment and pollEnrich in the current exchange

Neither enrichment nor pollEnrich can use any information from the current exchange. This means, for example, that you cannot save the file header on the exchange for pollEnrich to use select a specific file. This may change in the future if the Camel team can find a solution.

However, to implement the aggregation strategy, they provide a code example similar to the one below:

 public class ExampleAggregationStrategy implements AggregationStrategy { public Exchange aggregate(Exchange original, Exchange resource) { Object originalBody = original.getIn().getBody(); Object resourceResponse = resource.getIn().getBody(); Object mergeResult = ... // combine original body and resource response if (original.getPattern().isOutCapable()) { original.getOut().setBody(mergeResult); } else { original.getIn().setBody(mergeResult); } return original; } } 

In this example, I see that they have access to Exchange original , isn't this the current exchange? If not, then what kind of exchange is an "initial exchange"? And what do they mean by "current exchange"?

+6
source share
1 answer

Here is the difference:

  • enrich assumes that you want to use inbound Exchange as a parameter for another service request. for example, your inbound Exchange may be a user identifier, but you really need the entire User object, so you can enrich it by passing the userID to the REST service, which returns the User object that becomes Exchange, etc.

  • pollEnrich assumes that inbound Exchange is a simple trigger that tells PollingConsumer to search for data and creates Exchange (ignoring the contents of the incoming Exchange). For example, you may have a timer or other business process event that requires collecting a file for processing, etc. Then the Exchange incoming data is NOT used to dynamically configure PollingConsumer ... only URIs are used for this.

However, with Camel 2.12, it is possible to specify an aggregation strategy to combine incoming / return exchanges for enrich and pollEnrich

See this unit test for an example pollEnrich aggregation strategy.

+12
source

Source: https://habr.com/ru/post/954956/


All Articles