Skip to content

Commit 252bfab

Browse files
authored
Add support for graceful shutdown (#1030)
* Shutdown gracefully http server Signed-off-by: Marc Lallaouret <[email protected]> * Feedback from strimzi maintainer Signed-off-by: Marc Lallaouret <[email protected]> --------- Signed-off-by: Marc Lallaouret <[email protected]>
1 parent b62290c commit 252bfab

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/java/io/strimzi/kafka/bridge/Application.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ private static Future<HttpBridge> deployHttpBridge(BridgeConfig bridgeConfig)
8585
vertx.deployVerticle(httpBridge)
8686
.onSuccess(deploymentId -> {
8787
LOGGER.info("HTTP verticle instance [{}] deployed", deploymentId);
88+
89+
// Register shutdown hook for graceful shutdown
90+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
91+
LOGGER.info("Shutdown hook triggered, starting graceful shutdown...");
92+
vertx.close()
93+
.onComplete(ar -> {
94+
if (ar.succeeded()) {
95+
LOGGER.info("Vertx instance closed successfully");
96+
} else {
97+
LOGGER.error("Error closing Vertx instance", ar.cause());
98+
}
99+
});
100+
}));
88101
httpPromise.complete(httpBridge);
89102
})
90103
.onFailure(t -> {

src/main/java/io/strimzi/kafka/bridge/http/HttpBridge.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public void stop(Promise<Void> stopPromise) {
305305

306306
if (this.httpServer != null) {
307307

308-
this.httpServer.close()
308+
this.httpServer.shutdown()
309309
.onSuccess(v -> {
310310
LOGGER.info("HTTP-Kafka bridge has been shut down successfully");
311311
stopPromise.complete();

0 commit comments

Comments
 (0)