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?

TuGordoBello
  • 4,350
  • 9
  • 52
  • 78
Ocelot
  • 1,733
  • 4
  • 29
  • 53

1 Answers1

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();
    }
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • 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! – Ocelot Aug 06 '15 at 00:42
  • 1
    Please, ask that question in the separate SO thread. It doesn't relate to the current one. – Artem Bilan Aug 06 '15 at 01:09
  • Sure, new thread here: http://stackoverflow.com/questions/31845269/spring-integration-how-to-use-inbound-channel-adapter-to-check-a-directory-for – Ocelot Aug 06 '15 at 01:15