2
votes

I have a route that reads from an FTP server, then processes the message. The route has DeadLetterChannel error handler that routes the message to some bean when an exception is thrown while processing the message.

Now when an exception is handled by the error handler, Camel presumes everything passed fine and still deletes the FTP file.

If I remove the error handler, Camel doesn't delete the file when there is an exception.

Now my question is, how can i have a DeadLetterChannel error handler and at the same time stop Camel from deleting FTP file when processing fails?

2

2 Answers

2
votes

You can set the option noop=true on the ftp endpoint. Then the file will be left alone.

Though you would then have to consider how you can skip picking up the files in the future? And for that you can use the idempotent repository to keep track of which files you have processed before. Or an alternative is to move the file when you are done etc.

As the ftp component extends the file component see details at: http://camel.apache.org/file2

1
votes

You have several options to do that:

  1. You do not use the delete=true option at all and handle the delete of the file in the "success" scenario by yourself. This would be relatively transparent.
  2. In case you enter the DLC you can manipulate the endpoint from which you are consuming. Therefore just define your own processor for the DLC in onPrepareFailure. See example: deadLetterChannel("jms:dlc").onPrepareFailure(new ErrorProcessor()) After that you can use the getContext() method to get the camel context and one of the getEndpoint() methods to get your consumer endpoint. When you have the endpoint you can see which 'process factory' class is used with the getProcessStrategyand there you can update the delete flag to avoid deleting your file. For this endpoint it is also possible to define your own 'processStrategy' class with the method setProcessStrategy. Please take a look for yourself which process strategy class is used in your case. You then can override the according delete method like deleteLocalWorkFile and just do nothing.