Reputation: 67
I am using @InboundChannelAdapter
annotaion in a java class for polling files from a directory.
How can we prevent duplicate file polling in this?
Upvotes: 1
Views: 1324
Reputation: 121560
To configure file polling process via Annotations you should do something like this:
@Bean
@InboundChannelAdapter(value = "filesChannel", poller = @Poller(fixed-rate = "5000"))
public MessageSource<File> fileReadingMessageSource() {
FileReadingMessageSource source = new FileReadingMessageSource();
source.setDirectory(new File(INBOUND_PATH));
source.setAutoCreateDirectory(false);
source.setFilter(new AcceptOnceFileListFilter<>());
return source;
}
The same can be achieved with more simple way using Spring Integration Java DSL:
@Bean
public IntegrationFlow fileReadingFlow() {
return IntegrationFlows
.from(s -> s.file(tmpDir.getRoot()).patternFilter("*.sitest"),
e -> e.poller(Pollers.fixedDelay(100)))
.transform(Transformers.fileToString())
.aggregate(a -> a.correlationExpression("1")
.releaseStrategy(g -> g.size() == 25))
.channel(MessageChannels.queue("fileReadingResultChannel"))
.get();
}
Another your question can be resolved with the DSL as well, but it is definitely the separate SO question...
Upvotes: 4