Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用S3消息处理程序和Spring集成动态设置S3 bucket_Spring_Amazon S3_Spring Integration_Spring Integration Aws - Fatal编程技术网

使用S3消息处理程序和Spring集成动态设置S3 bucket

使用S3消息处理程序和Spring集成动态设置S3 bucket,spring,amazon-s3,spring-integration,spring-integration-aws,Spring,Amazon S3,Spring Integration,Spring Integration Aws,如何使用Spring集成将“资产”POJO传递给S3MessageHandler并更改bucket 我希望能够根据资产中的文件夹将bucket更改为类似“根bucket/a/b/c”的内容 每个资源可能具有不同的子路径 @Bean IntegrationFlow flowUploadAssetToS3() { return flow -> flow .channel(this.channelUploadAsset)

如何使用Spring集成将“资产”POJO传递给S3MessageHandler并更改bucket

我希望能够根据资产中的文件夹将bucket更改为类似“根bucket/a/b/c”的内容

每个资源可能具有不同的子路径

    @Bean
    IntegrationFlow flowUploadAssetToS3()
    {
        return flow -> flow
            .channel(this.channelUploadAsset)
            .channel(c -> c.queue(10))
            .publishSubscribeChannel(c -> c
                .subscribe(s -> s
                    // Publish the asset?
                    .<File>handle((p, h) -> this.publishS3Asset(
                        p,
                        (Asset)h.get("asset")))
                    // Set the action
                    .enrichHeaders(e -> e
                        .header("s3Command", Command.UPLOAD.name()))
                    // Upload the file
                    .handle(this.s3MessageHandler())));
    }

    MessageHandler s3MessageHandler()
    {
        return new S3MessageHandler(amazonS3, "root-bucket");
    }

有一个
bucketExpression
选项,用于解析来自
requestMessage
的bucket:

 private static SpelExpressionParser PARSER = new SpelExpressionParser();

 MessageHandler s3MessageHandler() {
    Expression bucketExpression =
                PARSER.parseExpression("payload.bucketProperty");
    return new S3MessageHandler(amazonS3, bucketExpression);
}

还要注意,
根bucket/a/b/c.
不是bucket名称。你应该考虑区分桶和<代码>键<代码>来构建那个复杂的子文件夹路径。为此,有一个具有类似功能的
keyExpression
选项,用于根据
requestMessage

解析bucket中的密钥。出于好奇,我可以通过上面的DSL设置这些表达式,还是必须在返回处理程序的方法中?AWS通道适配器没有Java DSL。因此,您必须直接使用
S3MessageHandler
的setter和ctor。
 private static SpelExpressionParser PARSER = new SpelExpressionParser();

 MessageHandler s3MessageHandler() {
    Expression bucketExpression =
                PARSER.parseExpression("payload.bucketProperty");
    return new S3MessageHandler(amazonS3, bucketExpression);
}