Hi

The CamelAggregatedSize is actually an exchange property that the
aggregate EIP sets.

However due to historical reasons the ${header.xxx}} does a fallback
and lookup the exchange properties if the header is missing.
So that is why it works on the 1st and not the 2nd. In the 2nd use
exchange.getProperty instead

On Mon, Jan 7, 2019 at 10:17 PM Rajith Muditha Attapattu
<rajit...@gmail.com> wrote:
>
> I have an aggregator that aggregates on size or completion interval.
> For operational purposes, we want to log the aggregate size.
>
> In the same route, we have both the following statements. (The first
> statement was added for debuging.) However in the second statement when
> accessing it via exchange.getIn().getHeader("CamelAggregatedSize",
> Integer.class), I get a NPE bcos that header is missing. I'm wondering what
> I'm missing ?
>
> .log(LoggingLevel.INFO, ROUTE_NAME + " Aggregate size =
> ${header.CamelAggregatedSize} "
>                         + "Aggregate Completed By =
> ${header.CamelAggregatedCompletedBy}")
>
> .process((Exchange exchange) -> {
>                 ElasticLogger.logMetric("xxxxxx", "AGG_SIZE", "count",
> exchange.getIn().getHeader("CamelAggregatedSize", Integer.class));
>                 })
>
> I'm not sure why the first statement is able to pick the correct header and
> why the very same header is missing in the next statement.
> I even added the following before and after the above two statements to see
> if there's a difference in the headers. I can see that in both cases the
> CamelAggregatedSize is missing.
>
>                .process((Exchange exchange) -> {
>                 Map<String, Object> headers = exchange.getIn().getHeaders();
>             LOG.info ("========= headers after aggregation  - part 2
> ====================");
>             for (String key: headers.keySet()) {
>             LOG.info(String.format("%s : %s", key, headers.get(key)));
>             }
>             LOG.info
> ("========================================================");
>                 })
>
> Regards,
>
> Rajith Muditha Attapattu <http://rajith.2rlabs.com/>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to