Hi,
I've been trying to find a way to shut down a Vert.x application gracefully, but so far, had no success.
My application uses Vert.x 3.4.1 (recently migrated from 3.3.3), exposing an HTTP server that handles some requests and triggers HTTP calls to downstream services. Whenever I stop it with an SIGINT (Ctrl-C or kill -2 <pid>) or SIGTERM, all client connections to my server are abruptly closed and no response is returned.
I'm trying to find a way to save these requests.
--
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.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/b2fd3fd6-2051-4fac-9d95-57a8dedf6164%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Tim,
Sorry if it was confusing/not clear.
I'm looking for a way to finish processing all requests that started prior to my application shutdown. There are mechanisms in place already to ensure no new requests will be accepted by my app, but I want to save what has already been accepted.
For example, if a client makes a request to my application and I stop the server before a response is sent to the client, I want to delay the shutdown
public class ShutdownVerticle extends AbstractVerticle {
private static final Logger LOGGER = LoggerFactory.getLogger(ShutdownVerticle.class);
@Override
public void start(Future<Void> startFuture) throws Exception {
vertx.createHttpServer().requestHandler(request -> {
int shutdownTimer = 60000;
LOGGER.info("Preparing to shutdown in {} milliseconds", shutdownTimer);
vertx.setTimer(shutdownTimer, id -> {
vertx.close(result -> {
if (!result.succeeded()) {
LOGGER.info("Goodbye, world.");
}
});
});
request.response().end();
}).listen(8092);
}
}
rabbitMQClient!!.start { res ->
if (res.succeeded()) {
val autoAck = true
rabbitMQClient!!.basicConsume("fromThemToUs", "fromThemToUs", autoAck, {
if (it.succeeded()) { logger.info("successfully consumed") }
else { logger.error(it.cause().stackTrace) }
})
} else {
logger.error("Failed to connect to rabbit with ${rabbitConfig.getConfig()}")
}
}
Why not?Usually, you put some kind of router before application. Zero downtime updates are not hard to archive with nginx.
On Wednesday, 24 May 2017 09:34:27 UTC+1, Dmitrii Golub wrote:Why not?Usually, you put some kind of router before application. Zero downtime updates are not hard to archive with nginx.It's not possible with Vert.x alone (or Node.js alone, or anything else), of course if you put an intelligent proxy or load balancer on the front which has the ability to count requests and responses sent to each server and switch them over when there are no outstanding then you can achieve what you want, but that#s what
On Wednesday, 24 May 2017 09:34:27 UTC+1, Dmitrii Golub wrote:Why not?Usually, you put some kind of router before application. Zero downtime updates are not hard to archive with nginx.It's not possible with Vert.x alone (or Node.js alone, or anything else), of course if you put an intelligent proxy or load balancer on the front which has the ability to count requests and responses sent to each server and switch them over when there are no outstanding then you can achieve what you want, but that#s what was asked in the original question.
I have no idea how to handle this case:1. verticle receives sigterm2. rabbitMQClient stop receiving new messages3. Wait while verticle consume the last message4. Shutdown instance.You told that this is possible, could you please give me directions.
Yes, you are right that original question, my question, and rabbitmq question are all different.But they are about the same thing.What's the way to stop application gracefully, only after very last in progress request?
Smart LB is not the solution, as you can first request 200, and that would be a trigger to start some heavy task in your verticle.Graceful in that case means that you'll wait for that task to complete.What about me, that code is part of finance application, and I have no idea how to restart consumer verticle.It's crucial here not to interrupt in progress job.