服务停止时未执行 Vertx 停止方法
Vertx stop method not executed on service stop
当我停止服务时,停止不会被调用,但如果在测试用例中尝试相同的方法,我部署和取消部署带有部署 ID 的 Verticle,停止方法正在执行。
编辑:-
我正在创建 jar 文件(不是影子 Jar)。
下面是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(' ')
)
}
}
开始申请:-
java -jar api-gateway-1.0.0-SNAPSHOT.jar -Dconfig.propertyFile="<property file path>" -DlogfilePath="<log file path>"
正在停止应用程序:-
CTRL+C
创建 CustomLauncher 扩展启动器 class 有效。
@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 变化:-
jar {
manifest {
attributes(
"Manifest-Version": "1.0",
"Main-Verticle": "LauncherVerticle",
"Main-Class": "CustomLauncher",
"Class-Path": configurations.runtimeClasspath.collect { it.getName() }.join(' ')
)
}
}
当我停止服务时,停止不会被调用,但如果在测试用例中尝试相同的方法,我部署和取消部署带有部署 ID 的 Verticle,停止方法正在执行。
编辑:- 我正在创建 jar 文件(不是影子 Jar)。 下面是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(' ')
)
}
}
开始申请:-
java -jar api-gateway-1.0.0-SNAPSHOT.jar -Dconfig.propertyFile="<property file path>" -DlogfilePath="<log file path>"
正在停止应用程序:-
CTRL+C
创建 CustomLauncher 扩展启动器 class 有效。
@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 变化:-
jar {
manifest {
attributes(
"Manifest-Version": "1.0",
"Main-Verticle": "LauncherVerticle",
"Main-Class": "CustomLauncher",
"Class-Path": configurations.runtimeClasspath.collect { it.getName() }.join(' ')
)
}
}