简体   繁体   English

一个优雅的异步解决方案,用于从 Java 中的 Vertx 工作程序 Verticle 将文件从 S3 发送到客户端

[英]An elegant async solution to send a file from S3 to the client from a Vertx worker verticle in Java

I have a Vertx server with a worker vertical to asynchronously handle requests for S3 operations.我有一个 Vertx 服务器,它带有一个垂直的工作线程来异步处理 S3 操作的请求。 We need a solution to transfer a file from S3 to the client through our server.我们需要一个解决方案,通过我们的服务器将文件从 S3 传输到客户端。 A previous question Streaming S3 object to VertX Http Server Response is answered by tsegismont, but it appears that the recommendation would block the Vertx thread.以前的问题Streaming S3 object to VertX Http 服务器响应由 tsegismont 回答,但似乎该建议会阻止 Vertx 线程。 The file transfer belongs in a separate vertical.文件传输属于单独的垂直。 This recommended solution would not work in a worker vertical since The RoutingContext is not sent across the bus as recommended by How can I send RoutingContext object from routing vertical to some other vertical using vertx.eventBus().send() method?这个推荐的解决方案在工作人员垂直中不起作用,因为 RoutingContext 没有按照如何使用 vertx.eventBus().send() 方法将 RoutingContext object 从路由垂直发送到其他垂直的建议通过总线发送? . . Note that here it seems the recommended solution, to create a special codec, would not work since a RoutingContext is required in the worker vertical.请注意,这里似乎推荐的解决方案(创建特殊编解码器)不起作用,因为在工作人员垂直中需要 RoutingContext。

Another solution would be to get the object from S3.另一种解决方案是从 S3 获取 object。 Save it to file.将其保存到文件中。 Then use the fileSend method in WebClient API to send to the client.然后使用WebClient API中的fileSend方法发送给客户端。 This... is not an elegant solution.这...不是一个优雅的解决方案。

A third solution would be to abandon the WorkerVertical and use the blockingHandler method in the MainVertical.第三种解决方案是放弃 WorkerVertical 并在 MainVertical 中使用 blockingHandler 方法。 This is not an async call.这不是异步调用。 The thread would not be released for potentially seconds and is worse than the previous solution.该线程可能会在几秒钟内不会被释放,并且比以前的解决方案更糟糕。

I don't know if its an option for you, but you can utilize presigned url - https://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURL.html我不知道它是否适合您,但您可以使用预签名的 url - https://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURL.ZFC35FDC70D5FC69D526

What I do most of the time is using the vertx server to handle coordination and generate presigned url's to get/upload files from s3.我大部分时间做的是使用 vertx 服务器来处理协调并生成预签名的 url 以从 s3 获取/上传文件。

The client get the presigned URL and can download / upload directly to s3 while protecting the actual credentials via the backend.客户端获得预签名的 URL 并可以直接下载/上传到 s3,同时通过后端保护实际凭据。

The presigned URL can have limited lifetime and you get all the scalability of AWS without dealing with file streaming / out-of-memory exceptions / etc.预签名的 URL 的生命周期可能有限,您可以获得 AWS 的所有可扩展性,而无需处理文件流/内存不足异常等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM