Is there an option/way in FileReadingMessageSource
to delete file after running receive()
method?
Thanks.
Is there an option/way in FileReadingMessageSource
to delete file after running receive()
method?
Thanks.
You can do that with this (xml sample):
<int:poller fixed-rate="500">
<int:transactional synchronization-factory="syncFactory"/>
</int:poller>
<int:transaction-synchronization-factory id="syncFactory">
<int:after-commit expression="payload.delete()"/>
</int:transaction-synchronization-factory>
where that <poller>
is for <int-file:inbound-channel-adapter>
As a transactionManager
you can use PseudoTransactionManager
: http://docs.spring.io/spring-integration/docs/latest-ga/reference/html/transactions.html
In your method for the message handler use setDeleteSourceFiles(true), see below:
@Bean
@InboundChannelAdapter(value = FILE_CHANNEL_SOURCE, poller =
@Poller(fixedDelay = INTERVAL))
public MessageSource<File> sourceFiles() {
FileReadingMessageSource source = new FileReadingMessageSource();
source.setAutoCreateDirectory(true);
source.setDirectory(new File(sourceDir));
source.setFilter(new SimplePatternFileListFilter(FILE_PATTERN));
return source;
}
@Bean
@ServiceActivator(inputChannel = FILE_CHANNEL_SOURCE)
public MessageHandler processedFiles() {
FileWritingMessageHandler handler = new FileWritingMessageHandler(new File(outputDir));
handler.setFileExistsMode(FileExistsMode.FAIL);
handler.setDeleteSourceFiles(true);
handler.setExpectReply(false);
return handler;
}