如何使用 Spring Integration 将“资产”POJO 传递给 S3MessageHandler 并更改存储桶?
我希望能够根据资产中的文件夹将存储桶更改为“root-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");
}
感谢下面的答案,我得到了这样的工作:
final String bucket = "'my-root";
final Expression bucketExpression = PARSER.parseExpression(bucket);
final Expression keyExpression = PARSER.parseExpression("headers['asset'].bucket");
final S3MessageHandler handler = new S3MessageHandler(amazonS3, bucketExpression);
handler.setKeyExpression(keyExpression);
return handler;