如何使用S3InboundFileSynchronizer同步组织目录的S3Bucket?

时间:2016-08-08 19:12:43

标签: spring amazon-web-services amazon-s3 spring-integration

我正在尝试使用S3InboundFileSynchronizer将S3Bucket同步到本地目录。存储桶的子目录如下:

bucket -> 2016 -> 08 -> daily-report-20160801.csv daily-report-20160802.csv 等...

使用此配置:

@Bean
        public S3InboundFileSynchronizer s3InboundFileSynchronizer() {
            S3InboundFileSynchronizer synchronizer = new S3InboundFileSynchronizer(amazonS3());
            synchronizer.setDeleteRemoteFiles(true);
            synchronizer.setPreserveTimestamp(true);
            synchronizer.setRemoteDirectory("REDACTED");
            synchronizer.setFilter(new S3RegexPatternFileListFilter(".*\\.csv$"));
            Expression expression = PARSER.parseExpression("#this.substring(#this.lastIndexOf('/')+1)");
            synchronizer.setLocalFilenameGeneratorExpression(expression);
            return synchronizer;
        }

我能够连接到存储桶并列出其内容。当从桶读取时,抛出以下异常:

org.springframework.messaging.MessagingException: Problem occurred while synchronizing remote to local directory; nested exception is   
org.springframework.messaging.MessagingException: Failed to execute on session; 
nested exception is 
java.lang.IllegalStateException: 'path' must in pattern [BUCKET/KEY].
at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:266)

查看代码似乎无法同步S3Bucket w /子目录:

private String[] splitPathToBucketAndKey(String path) {
    Assert.hasText(path, "'path' must not be empty String.");
    String[] bucketKey = path.split("/");
    Assert.state(bucketKey.length == 2, "'path' must in pattern [BUCKET/KEY].");
    Assert.state(bucketKey[0].length() >= 3, "S3 bucket name must be at least 3 characters long.");
    bucketKey[0] = resolveBucket(bucketKey[0]);
    return bucketKey;
} 

我是否缺少某些配置或这是一个错误?

(我假设这是一个错误',直到我被告知其他情况,所以我提交了pull request并提出了建议修复。)

1 个答案:

答案 0 :(得分:0)

是的,这是一个错误,提交的PullRequest很适合修复。

只有作为变通方法的解决方案类似于自定义SessionFactory<S3ObjectSummary>,它会返回自定义S3Session扩展名,其中包含PR中提供的修补程序。