camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: file processing, error handling
Date Fri, 07 Aug 2009 10:08:50 GMT
Hi

I have created the ticket
https://issues.apache.org/activemq/browse/CAMEL-1887

And I have just committed the feature to trunk so it should be there
in 2.0 when its released.

You can try it out by either
- waiting for a SNAPSHOT to be build and published to apache maven repo
- build from source

See more at download and camel home page.

The commit log
http://svn.apache.org/viewvc?rev=801928&view=rev

With unit tests demoing it

On Fri, Aug 7, 2009 at 10:54 AM, Claus Ibsen<claus.ibsen@gmail.com> wrote:
> On Fri, Aug 7, 2009 at 10:44 AM, arhan<ant.arhipov@gmail.com> wrote:
>>
>> Hi,
>>
>>
>> I have a case where the files are being consumed from a directory (quite
>> simple), processed, and backed up:
>>
>> public void configure() {
>>   String filesUri = "file:files" +
>>
>> "?move=files/backup/${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.xml";
>>
>>   from(filesUri)
>>     .process(new Processor() {
>>       public void process(Exchange exchange) throws Exception {
>>         //some processing done here
>>       }
>>     })
>>     .to("log:mylogger?level=DEBUG");
>>  }
>>
>> now, if the processing fails (some business logic issues), and the processor
>> throws an exception, I'm required to rename the file to, adding an 'error'
>> suffix. Here's what I did:
>>
>> public void configure() {
>>   String filesUri = "file:files" +
>>
>> "?move=files/backup/${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.xml";
>>
>>   onException(Exception.class).handled(true).
>>
>> to("file:files/error?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.xml.error").
>>   end();
>>
>>   from(filesUri)
>>     .process(new Processor() {
>>       public void process(Exchange exchange) throws Exception {
>>         exchange.setException(new Exception("could not process file "));
>>         //throw new Exception("could not process file ");
>>       }
>>     })
>>     .to("log:mylogger?level=DEBUG");
>>  }
>>
>>
>> Now the exception is being handled, and the file is renamed to
>> 'file.xml.error', but the move expression still handles the file as if it
>> was successfully handled, so that same copy of the file is now in
>> files/backup and files/error directories. Could there be a way to move the
>> failed files only once, without copying the failed file to files/backup?
>
> Hi
>
> Interesting use-case I guess we need to move expressions, one for
> success and one for failure to give you full power.
>
> You can use onCompletion on your file route and then move the file
> yourself as you got callbacks for onCompletion = OK, onFailure = ERROR
> And set noop=true on the file endpoint instead of move option.
>
> But let me create a ticket for the moveFailure option, so we can try
> to get it in 2.0 before it goes final.
> I recall other have had similar use case before.
>
>
>
>> --
>> View this message in context: http://www.nabble.com/file-processing%2C-error-handling-tp24861063p24861063.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message