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

1

5

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?

Scincoid answered 5/8, 2015 at 2:44 Comment(0)
C
8

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();
    }
Corneliacornelian answered 5/8, 2015 at 14:18 Comment(3)
Thanks for the response, it works. Also, I've updated the question requesting a bit more information, Would be great if you could have a look. Cheers!Scincoid
Please, ask that question in the separate SO thread. It doesn't relate to the current one.Corneliacornelian
Sure, new thread here: #31845769Scincoid

© 2022 - 2024 — McMap. All rights reserved.