Search code examples
springspring-bootspring-integrationspring-integration-sftpspring-integration-aws

NFS inbound adapter configuration for multiple directory using single inbound adapter


In spring integration, I want to poll files from different source directories (each interface configured have different source directories) which is configured in as sourcePath in yml file (dynamically) like below. N number of interfaces can be added by user.

 interfaces:
      -
        sourceType: NFS
        sourcePath: /Interface-1/Inbound/text
        target: Interface-1
        targetType: S3
        targetPath: test-bucket-1
      -
        sourceType: NFS
        sourcePath: /Interface-2/Inbound/text
        target: Interface-2
        targetType: S3
        targetPath: test-bucket-2

Is it possible to poll the files from different source folders using single inbound adapter (using atomic reference) or need more than one inbound adapter?

Currently application polls files from base directory.

   <file:inbound-channel-adapter id="filesInboundChannel"
    directory="file:${base.path}" auto-startup="false" scanner="scanner" auto-create-directory="true">

    <integration:poller id="poller" max-messages-per-poll="${max.messages.per.poll}" fixed-rate="${message.read.frequency}" task-executor="pollingExecutor">
        <integration:transactional transaction-manager="transactionManager" />
    </integration:poller>       
  </file:inbound-channel-adapter>

Can someone give an advice on this or is there any other way can also achieve the same goal


Solution

  • Yes, you can use a single <file:inbound-channel-adapter> for this task. To make it rotate over a list of directories for scanning you need to configure an AbstractMessageSourceAdvice implementation for the <poller> of that adapter to change a directory when afterReceive(boolean messageReceived, MessageSource<?> source) gets a false for the receive operation. So, this way the next poll will get already a new directory for scanning.

    As a sample you can take a look into the recently introduced a RotatingServerAdvice: https://github.com/spring-projects/spring-integration/blob/master/spring-integration-file/src/main/java/org/springframework/integration/file/remote/aop/RotatingServerAdvice.java

    https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-channels-section.html#conditional-pollers