camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lsantos <leandro.bu...@globo.com>
Subject Cache api call result
Date Mon, 07 Nov 2016 15:00:44 GMT
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
View raw message