javaspringspring-integrationdslinbound

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?


Solution

  • 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();
        }