git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Count of number errors during split processed for reporting


Hi

You are falling into a trap that others have done as well, the
configure() method on RouteBuilder is only for setting up the route
and its invoked only once.

So when you do

     ) .log("FAILURECOUNT 1“+failCount);

That line is executed once and the string concat is evaluated to a constant:

"FAILURECOUNT 1" + 0

==>

"FAILURECOUNT 1 0

You can log from the processor as its an inlined anonymous class where
the method is invoked per message.



On Wed, Aug 1, 2018 at 10:42 PM, Peck, Sean <pecks2@xxxxxxxx> wrote:
> Fairly new to Camel, and am using it under springboot.
>
> I am attempting to get a Running Failure Count to report it after my route has completed…  Code is below.
> However I am having some sort of scope issue, or something, in my processor where I increment and log out the failCount variable, it properly increments and shows up in the log as 1 higher number for every error caught…
>
> However, any attempt to use the DSL .log.. such as .log(“FAILED COUNT :”+failCount), always Displays 0 for Failcount.
>
> IE, when the onException executes for the first time the log will show:
>
> FAILURECOUNT: 1
> FAILURECOUNT 1: 0
>
> On the secont failure handled:
> FAILURECOUNT: 2
> FAILURECOUNT 1: 0
>
> and of course the final report in the onCompletion always shows
>
> FAILURECOUNT 0
>
> So I am rather confused what is going on…
>
> I even tried to put the failurecount in a msg header, and this worked find for the onException, pulling the header and displaying it.. but the .log on the onCompletion, the header wasn’t passed through in its message.. So I am perplexed.. How do I do this?  I assume this should be pretty simple…
>
>
> @Component
> public class MyRoute extends RouteBuilder {
>
>    int failCount;
>
>     @Override
>     public void configure() {
>
>         onException(Exception.class)
>                 .maximumRedeliveries(0)
>                 .to("metrics:counter:OneContent Failure Count")
>
>                 .process(new Processor() {
>                              public void process(Exchange exchange) {
>
>                                  Do My Processing
>
>                                  failCount++;
>                                  LOG.info("FAILURECOUNT "+failCount);
>
>                              }
>                          }
>                 ) .log("FAILURECOUNT 1“+failCount);
>
>
>
>         from( props.getProperty("sourceFile")+"?move=.done&moveFailed=.error").routeId("OneContent Route")
>                                                .onCompletion().modeAfterConsumer()
> .log(“FAILURE COUNT:”+failCount);
>                .end()
>
>                 .to("bean:getShare")
>                 .unmarshal(csv)
>                 .split(body()).parallelProcessing(true)
>                     .to("bean:MyProcessor").to("metrics:counter:OneContent records processed")
>
>                 .end()
>                 .log("failed count: failCount);
>
>
>
>     }
> }
>



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