使用 xml Spring 与 Azure blob 存储集成

标签 spring azure spring-integration

使用文件适配器,我有一个入站 channel 以固定速率轮询,从目录中读取文件,过滤某些文件,最后对它们进行排序并将它们发送到出站网关,出站网关再次移动文件以供服务 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”/>

这是我们如何从文件系统读取文件的示例。

假设我想从 Azure blob 存储中读取文件,假设我有一个包含文件夹 A 的容器 X。使用帐户名和帐户访问 key ,我如何告诉 spring Integration 从容器 X 的文件夹 A 中读取文件.

首选 XML 配置。

最佳答案

我也遇到过和你遇到的问题类似的情况。 这是我解决问题的方法 -

  1. 创建了一个CloudStorageAccount的bean(您可以轻松地将其转换为xml配置。我不习惯xml配置。) -

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

  2. 使用AzureStorageProtocolResolver -

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

AzureStorageProtocolResolver 是一个 Azure 类,将在内部使用 beanfactory 中的 StorageAccount bean。 请参阅 - https://github.com/Microsoft/spring-cloud-azure/blob/master/spring-cloud-azure-storage/src/main/java/com/microsoft/azure/spring/cloud/storage/AzureStorageProtocolResolver.java

还有另一种方法,即使用Azure Spring Boot Starter。 请参阅 - https://github.com/Microsoft/azure-spring-boot/tree/master/azure-spring-boot-starters/azure-storage-spring-boot-starter

关于使用 xml Spring 与 Azure blob 存储集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54631534/

相关文章:

具有私有(private)构造函数的 Java Spring bean

java - 针对客户和员工的 Spring Security 用户身份验证

spring - 如何使用 jest 客户端或传输客户端在 Elasticsearch 中使用三个表单字段进行搜索

azure - 如何获取 Azure DevOps 当前迭代的开始日期?

c# - 间歇性System.ComponentModel.Win32Exception : The network path was not found

azure - 在aks中部署nginx-ingress,没有rbac问题

java - Spring Integration + 过滤器 + 向 REST Controller 发送 400 错误请求

java - 如何在 Spring 中添加来自另一个模块的 bean 依赖项?

java - 处理 FTP 列表中的所有消息后停止 Spring Integration 应用程序

java - Spring Integration - 入站文件端点。如何正确处理文件。