Sep 1st, 2008, 11:26 PM
Directory Polling with Delete
I'm sure it's a noob question, and I apologize for asking. I've spent a few days trying to create a simple directory poller that will delete the messages after consumption. My ultimate objective is to pull the files off the file system and post them to a MDB over JMS. The new file-source leaves the files.
Is there a way to do that with configuration, or am I better of to write a custom spring bean? I've seen references to a custom message creator, but haven't found config examples. Thanks in advance.
Sep 2nd, 2008, 01:54 AM
It's not a noob question. There has been some refactoring there, so this hasn't been documented properly yet. There are two options to this:
- Either implement your own MessageCreator and wire it as a bean, injected into the message-creator attribute of <file-source .../>.
- or clean up the files yourself.
I don't like the MessageCreator option really, the reasoning for this is as follows.
First of all, the AbstractDirectorySource subclasses use a Backlog to manage their work. This means that files that stay in the directory are only picked up once, even if you leave them there forever. This means that the only harm you can do by not deleting the files is wasting disk space.
The second thing is that the FileSource doesn't know about the writer of the file. There is no way to be sure when the writer is done. See http://jira.springframework.org/browse/INT-269.
This leads me to think that the best design would be to use an implementation of FileFilter that is controlled by the writer to show Files in the input directory that are written, and to have a component later in the chain let the writer know that the file has been picked up. You could replace the last part with a clean up strategy based on the date of the file.
I hope this makes sense to you, don't hesitate to ask for clarification.
Tags for this Thread