Ketika saya menghentikan layanan, pemberhentian tidak dipanggil tetapi jika mencoba hal yang sama dalam kasus uji di mana saya menyebarkan dan melepaskan verticle dengan ID penyebaran, metode berhenti dijalankan.

EDIT: - Saya membuat file jar (bukan Jar bayangan). Di bawah ini adalah konfigurasi build.gradle

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(' ')
        )
    }
}

Memulai aplikasi:-

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

Menghentikan aplikasi:-

CTRL+C

1
Ravat Tailor 19 November 2020, 09:41

1 menjawab

Jawaban Terbaik

Membuat CustomLauncher yang memperluas kelas Launcher berhasil.

@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();
    }
}

Perubahan build.gradle: -

jar {
    manifest {
        attributes(
                "Manifest-Version": "1.0",
                "Main-Verticle": "LauncherVerticle",
                "Main-Class": "CustomLauncher",
                "Class-Path": configurations.runtimeClasspath.collect { it.getName() }.join(' ')
        )
    }
}
1
Ravat Tailor 10 Desember 2020, 14:07