Using http client for file downloading

162 views
Skip to first unread message

Aravinda

unread,
Apr 30, 2021, 3:35:43 AM4/30/21
to vert.x
Hi Team,

I am trying to use, vertx 3.9.1 http client for downloading files. I want to set the maximum allowed time for a particular download and fail if it exceeds. Is there a way to achieve this via read-Timeout or any other means in vertx.?

vertx.fileSystem().open("/my-file.wav", new OpenOptions(), new Handler<AsyncResult<AsyncFile>>() {
            @Override
            public void handle(AsyncResult<AsyncFile> event) {
                webClient
                        .get(8080, "myserver.mycompany.com", "/some-uri/remote-file.wav")
                        .as(BodyCodec.pipe(event.result()))
                        .send(new Handler<>() {
                            @Override
                            public void handle(AsyncResult<HttpResponse<Void>> event) {
                                    //rest of the stuff
                            }
                        });
            }
        });

Thanks.
Best Regards,
Aravinda

Thomas SEGISMONT

unread,
Apr 30, 2021, 4:20:22 AM4/30/21
to vert.x
Hi,

You can't cancel a request that has been scheduled as far as I know.

In your verticle code you could set a timer that fires after the maximum time allowed before executing the request.
Then in the request callback you check if you can cancel the timer. If you can, it means the timer has not fired so you may proceed normally. Otherwise, drop the result.

HTH

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/89ad874d-4ec0-457c-991f-2f8474817605n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages