1
如何使用Spring集成將「資產」POJO傳遞到S3MessageHandler並更改存儲桶?使用S3消息處理程序和Spring集成動態地設置S3存儲桶
我希望能夠根據資產中的文件夾將存儲桶更改爲「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;
出於好奇,我可以通過上面的DSL設置這些表達式,還是必須在返回處理程序的方法中? – KJQ
AWS Channel Adapter沒有Java DSL。所以,你必須直接使用'S3MessageHandler'的setter和ctors。 –