【问题标题】:spring-integration-aws - disable sync from sub folders in bucketspring-integration-aws - 禁用桶中子文件夹的同步
【发布时间】:2018-09-15 22:29:25
【问题描述】:

我在我的一个项目中使用 Spring 集成 Aws 将文件从 S3 存储桶下载到本地目录。我已经指定了存储桶的位置,到目前为止下载工作正常。当我在存储桶中创建一个子文件夹以保存存档文件(已处理/下载)时,出现了问题。 S3 同步器也开始下载子文件夹。我的期望是只同步存储桶中的文件夹而不是子文件夹。我可以在 spring-integration-aws 0.5 版本中看到一个标志来禁用此行为。

<xsd:attribute name="accept-sub-folders" type="xsd:string">

但我在 2.00 版中找不到这个。

下面是代码:

@Bean
public S3InboundFileSynchronizer s3InboundFileSynchronizer ()
{
    S3InboundFileSynchronizer s3InboundFileSynchronizer = new S3InboundFileSynchronizer (amazonS3);
    s3InboundFileSynchronizer.setDeleteRemoteFiles (false);
    s3InboundFileSynchronizer.setPreserveTimestamp (true);
    s3InboundFileSynchronizer.setRemoteDirectory (remoteBucket);
    ChainFileListFilter fileListFilter = new ChainFileListFilter ();
    fileListFilter.addFilter (new S3RegexPatternFileListFilter (remoteFilesExtension));
    fileListFilter.addFilter (new S3PersistentAcceptOnceFileListFilter (metadataStore (), metadataStoreKeyPrefix));
    return s3InboundFileSynchronizer;
}

和轮询器配置:

@Bean
@InboundChannelAdapter(channel = "fileArchiveChannel", poller = @Poller(fixedRate = "100000", maxMessagesPerPoll = "-1"))
public S3InboundFileSynchronizingMessageSource s3InboundFileSynchronizingMessageSource ()
{
    S3InboundFileSynchronizingMessageSource messageSource = new S3InboundFileSynchronizingMessageSource (s3InboundFileSynchronizer ());
    messageSource.setAutoCreateLocalDirectory (true);
    messageSource.setLoggingEnabled (true);
    File location = new File (localDirectory);
    Assert.notNull (location, "Local directory is not available");
    messageSource.setLocalDirectory (location);

    ChainFileListFilter fileListFilter = new ChainFileListFilter ();
    fileListFilter.addFilter (new RegexPatternFileListFilter (remoteFilesExtension));
    fileListFilter.addFilter (new FileSystemPersistentAcceptOnceFileListFilter (metadataStore (), metadataStoreKeyPrefix));
    messageSource.setLocalFilter (fileListFilter);

    return messageSource;
}

有什么方法可以停止将子文件夹与 spring integration aws 2.00 同步?

【问题讨论】:

    标签: spring spring-integration spring-integration-aws


    【解决方案1】:

    据我所知,AWS S3 协议中没有 sub-folder 表示法:https://docs.aws.amazon.com/AmazonS3/latest/user-guide/using-folders.html

    这是对具有相同前缀的对象进行分组的人为方法。

    当我们从 S3 获得一个对象时,我们就有了它的密钥。因此,您可以配置 S3RegexPatternFileListFilter 以跳过那些其键具有您的逻辑子文件夹名称的对象。

    【讨论】:

    • 谢谢阿特姆。我现在使用正则表达式模式来跳过存档文件夹。我希望如果这可以使用属性来完成。
    • 那不是因为它在 AWS S3 中没有意义
    • 同意。谢谢。
    【解决方案2】:

    为了解决这个问题,我更新了正则表达式模式以排除包含 S3RegexPatterenFileListFilter 的存档文件夹路径的文件。此模式仅允许带有 txt csv 扩展名的文件,但不允许带有我的存档文件夹名称的路径。

    ([^archive](\.(?i)(txt|csv))$)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-30
      相关资源
      最近更新 更多