2
votes

Using file adapter I have an inbound channel polling at fixed rate reading the files from a directory, filtering certain files and finally sorting them and sending them to the outbound gateway which again moves the files for processing by a service bean.

<bean id="baseDirectory" class="java.lang.String">
    <constructor-arg value="${HOME}/user/files/"/>
</bean>

<file:inbound-channel-adapter id="testFiles" directory="#{baseDirectory}" filename-regex="^(test_filename.*)-(\d+)\.csv" comparator="someFileOrderComparator">
    <int:poller fixed-rate="6000"/>
</file:inbound-channel-adapter>

<file:outbound-gateway request-channel="testFiles" reply-channel="testFile" directory="#{baseDirectory}/processing" delete-source-files="true”/>

<int:service-activator input-channel="testFile" ref="someServiceTask" method="executeTask”/>

This is an example of how we can read files from a file system.

Suppose I want to read the files from an Azure blob storage, say I have a container X which contains folder A. Using account name and account access key how can I tell spring Integration to read the files from folder A of container X.

XML configuration preferred.

1

1 Answers

2
votes

I have faced something similar to the problem you are facing. Here's how I solved it -

  1. created a bean of CloudStorageAccount (You can convert this into xml config easily. I'm not used to xml configuration.) -

    @Bean CloudStorageAccount getAccount(String connString){ return CloudStorageAccount.parse(connString); }

  2. Used AzureStorageProtocolResolver -

AzureStorageProtocolResolver fileResolver = new AzureStorageProtocolResolver(); File resolvedFile = fileResolver.resolve("azure-blob://<containerName>/<Path to File(e.g. "lib/myfile.jar")>").getFile();

AzureStorageProtocolResolver is an Azure class and will use the StorageAccount bean from beanfactory internally. See - https://github.com/Microsoft/spring-cloud-azure/blob/master/spring-cloud-azure-storage/src/main/java/com/microsoft/azure/spring/cloud/storage/AzureStorageProtocolResolver.java

There's another way at this using Azure Spring Boot Starter. See - https://github.com/Microsoft/azure-spring-boot/tree/master/azure-spring-boot-starters/azure-storage-spring-boot-starter