You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Rajith Muditha Attapattu <ra...@gmail.com> on 2019/01/07 21:17:10 UTC

Bizarre behaviour with Camel CamelAggregatedSize header

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/>

Re: Bizarre behaviour with Camel CamelAggregatedSize header

Posted by Rajith Muditha Attapattu <ra...@gmail.com>.
Thanks Claus, I knew it was a silly mistake on my part :D
(The doc clear says it's an exchange prop... I guess the
header.CamelAggregatedSize tripped me up).

On Tue, Jan 8, 2019 at 2:22 AM Claus Ibsen <cl...@gmail.com> wrote:

> 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
> <ra...@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
>


-- 
Regards,

Rajith Muditha Attapattu <http://rajith.2rlabs.com/>

Re: Bizarre behaviour with Camel CamelAggregatedSize header

Posted by Claus Ibsen <cl...@gmail.com>.
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
<ra...@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