Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring integration Java - how to use @InboundChannelAdapter to check a directory for files?

How can i get @InboundChannelAdapter to work with files? something like this:

<int-file:inbound-channel-adapter id="executionMessageFileInputChannel"
                                      directory="file:${fpml.messages.input}"
                                      prevent-duplicates="false" filename-pattern="*.xml">
        <int:poller fixed-delay="20000" max-messages-per-poll="1" />
</int-file:inbound-channel-adapter>

but in java?

like image 868
Ocelot Avatar asked Aug 05 '15 02:08

Ocelot


1 Answers

Something like this:

@Bean
@InboundChannelAdapter(value = "executionMessageFileInputChannel",
        poller = @Poller(fixedDelay = "20000", maxMessagesPerPoll = "1"))
public MessageSource<File> fileMessageSource(@Value("${fpml.messages.input}") File directory) {
    FileReadingMessageSource fileReadingMessageSource = new FileReadingMessageSource();
    fileReadingMessageSource.setDirectory(directory);
    fileReadingMessageSource.setFilter(new SimplePatternFileListFilter("*.xml"));
    return fileReadingMessageSource;
}

From other side pay attention, please, to the Spring Integration Java DSL project, using which the same may look like:

    @Bean
    public IntegrationFlow fileReadingFlow(@Value("${fpml.messages.input}") File directory) {
        return IntegrationFlows
                .from(s -> s.file(directory).patternFilter("*.xml"),
                        e -> e.poller(Pollers.fixedDelay(20000)))
        .....................
                .get();
    }
like image 163
Artem Bilan Avatar answered Nov 15 '22 12:11

Artem Bilan