camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Taariq Levack <taar...@gmail.com>
Subject Re: Cache api call result
Date Mon, 07 Nov 2016 17:25:36 GMT
Hi,
You can use camel-ehcache,  something like this example from the old
camel-cache;

from("direct:start")
    // Prepare headers
    .setHeader(CacheConstants.CACHE_OPERATION,
constant(CacheConstants.CACHE_OPERATION_GET))
    .setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).
    .to("cache://TestCache1").
    // Check if entry was not found
    .choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNull()).
        // If not found, get the payload and put it to cache
        .to("cxf:bean:someHeavyweightOperation").
        .setHeader(CacheConstants.CACHE_OPERATION,
constant(CacheConstants.CACHE_OPERATION_ADD))
        .setHeader(CacheConstants.CACHE_KEY,
constant("Ralph_Waldo_Emerson"))
        .to("cache://TestCache1")
    .end()
    .to("direct:nextPhase");

http://camel.apache.org/ehcache.html

Try modify the route to encapsulate your firstEnrichEndpoint.

Cheers

On 07 Nov 2016 17:06, "lsantos" <leandro.bueno@globo.com> wrote:

> Hi there,
>
> I am working on a command-line camel application that polls a directory for
> a file, reads it, process each line, modifies a piece of information on the
> line and rewrites it in new file.
>
> I have to make 2 http calls as part of the msg enrichment process, the
> first
> call is as authorization call that gets a json web token that is sent in
> the
> headers of the second http call.
>
> My route dsl looks something like this:
>
> from("{{consumerEndpoint}}")
>                 .validate(body().regex(FILE_HEADER_PATTERN))
>                 .split(body().tokenize())
>                     .choice()
>                         .when(body().regex(RECORD_LINE_PATTERN))
>                         .process(pluckOutTokenRecordProcessor())
>                         .setHeader(Exchange.HTTP_METHOD, constant("POST"))
>                         // call that I want its result cached for reuse
>                         .enrich("{{firstEnrichEndpoint}}",
> getFirstAggregationStrategy()) .setHeader(Exchange.HTTP_METHOD,
> constant("GET"))
>
> .enrich().simple("{{sndEnrichEndpoint}}").aggregationStrategy(
> getSndAggregationStrategy())
>                         .process(recordUpdaterProcessor())
>                     .end() //end choice
>                     .aggregate(header(FILE_NAME_ONLY),
> stringBodyAggregator())
>                     .convertBodyTo(String.class)
>                     .to("{{transferEndpoint}}")
>                 .end();
>
>
> It is all good and working, however, the file that gets processed in
> production has millions of lines and I do not want to have to make an extra
> authorization http call for each record that is processed, as the json web
> token is valid for 20 minutes before it expires which is less than what
> takes to process one entire file.
>
> I would like to keep the jwt auth token cached in memory for let's say 15
> minutes and refresh it periodically.
>
> I was wondering how is the best approach to achieve this goal. I know that
> camel ships with a timer component, but I never worked with it.
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Cache-api-call-result-tp5789849.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message