java - Apache Camel runs part of onCompletion and doesn't show stack trace -


i'm trying use camel poll-once route use file if it's present , log error if not.

by default route nothing if file not exist i've started adding consumer.sendemptymessagewhenidle=true uri. check null body decide whether log exception or continue:

    from(thefileuri)         .oncompletion()             .oncompleteonly()             .log("success")             .bean(theotheraction, "start")         .end()         .onexception(exception.class)             .logstacktrace(true)             .log(error, "failed load file")             .handled(true)         .end()         .choice()             .when(body().isnotnull())                 .to(next_route_uri)             .endchoice()             .otherwise()                 .throwexception(new filenotfoundexception(thefileuri))             .endchoice(); 

there 2 problems this:

  • if file missing, success log still happens (but not bean!)
  • the stack trace not printed

if there better way i'd welcome suggestions i'd know i'm doing wrong in method.

it's still not clear me going on. however, believe onexception call needs separated chain. looks me logstacktrace applies redelivery attempts. number of attempts defaults 0 , want. way access exception java dsl appears custom processor. the getexception() method return null if using handled(true) must use exchange.getproperty(exchange.exception_caught, exception.class).

i suspect log message oncompletion due running in parallel before exception aborts:

camel 2.13 or older - on completion runs in separate thread icon oncompletion runs in separate thread in parallel original route. therefore not intended influence outcome of original route. idea on completion spin off new thread eg send logs central log database, send email, send alterts monitoring system, store copy of result message etc. therefore if want work influence original route, not use oncompletion that. notice: if use unitofwork api mentioned in top of page, can register synchronization callback on exchange executed in original route. way allows custom code when route completed; how custom components can enlist on completion services need, eg file component work moves/deletes original file etc.

since want not run code on exception, think can abort route exception.

i have this:

    onexception(exception.class)         .handled(true)         .process(new processor()         {             @override             public void process(exchange anexchange) throws exception             {                 exception myexception = anexchange.getproperty(exchange.exception_caught, exception.class);                 logger.error("failed load", myexception);             }         });     from(thefileuri)         .choice()             .when(body().isnotnull())                 .to(next_route_uri)                 .log("success")                 .bean(theotheraction, "start")             .endchoice()             .otherwise()                 .throwexception(new filenotfoundexception(thefileuri)); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -