vert.xshutdown-hookvertx-verticle

Vertx stop method not executed on service stop


When I stop the service the stop is not getting called but if try the same in test case where I deploy and undeploy verticle with deployment ID the stop method is executing.

EDIT:- I am creating jar file (not a shadow Jar). Below is build.gradle configuration

application{
    mainClassName='io.vertx.core.Launcher'
}

def mainVerticleName = 'verticleName'

jar {
    manifest {
        attributes(
                "Manifest-Version": "1.0",
                "Main-Verticle": "$mainVerticleName",
                "Main-Class": "io.vertx.core.Launcher",
                "Class-Path": configurations.runtimeClasspath.collect { it.getName() }.join(' ')
        )
    }
}

starting application :-

java -jar api-gateway-1.0.0-SNAPSHOT.jar -Dconfig.propertyFile="<property file path>" -DlogfilePath="<log file path>"

stopping application :-

CTRL+C


Solution

  • Creating CustomLauncher extending Launcher class worked.

    @Log4j2
    public class CustomLauncher extends Launcher {
       
    
        public static void main(String[] args) {
            new CustomLauncher().dispatch(args);
        }
    
        @Override
        public void beforeStoppingVertx(Vertx vertx) {
            log.info(" beforeStoppingVertx Called ===========");
           cleanUPBeforeStoppingVerx();
        }
    
        @Override
        public void afterStoppingVertx() {
            log.info(" afterStoppingVertx Called ===========");
        }
    
        @Override
        public void beforeDeployingVerticle(DeploymentOptions deploymentOptions) {
            log.info(" beforeDeployingVerticle Called ===========");
        }
    
        @Override
        public void beforeStartingVertx(VertxOptions options) {
            log.info(" beforeStartingVertx Called ===========");
        }
    
       
        @Override
        public void afterStartingVertx(Vertx vertx) {
            log.info(" afterStartingVertx Called ===========");
        }
    
        @Override
        public void handleDeployFailed(Vertx vertx, String mainVerticle, DeploymentOptions deploymentOptions,
                                       Throwable cause) {
            log.info("handleDeployFailed *****************");
            vertx.close();
        }
    }
    

    build.gradle changes :-

    jar {
        manifest {
            attributes(
                    "Manifest-Version": "1.0",
                    "Main-Verticle": "LauncherVerticle",
                    "Main-Class": "CustomLauncher",
                    "Class-Path": configurations.runtimeClasspath.collect { it.getName() }.join(' ')
            )
        }
    }