This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Directory Polling with Delete

Sep 2nd, 2008, 12:26 AM

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.

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.