首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当节点js应用程序关闭时无法取消eureka的注册

当节点js应用程序关闭时无法取消eureka的注册
EN

Stack Overflow用户
提问于 2020-06-09 09:02:29
回答 1查看 226关注 0票数 0

我正在使用eureka - js -客户端与eureka发现服务器对节点js应用程序进行筛选。效果很好。但是,当节点js服务关闭时,它不会取消发现,并且在服务关闭后仍然显示为可用的实例。

在这里,我如何取消注册:

代码语言:javascript
复制
process.on('exit', function() {
  eurekaClient.stop() ;
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-21 07:07:15

我为节点js应用程序和eureka发现服务中的取消注册程序使用了exitHandelr。

代码语言:javascript
复制
process.stdin.resume();

function exitHandler(options, exitCode) {
    if (options.cleanup) console.log('clean');
    if (exitCode || exitCode === 0) console.log(exitCode);
    if (options.exit) {
        eurekaClient.stop(function (error) {
            process.exit();
        });
    }
}

//do something when app is closing
process.on('exit', exitHandler.bind(null, {cleanup: true}));

//catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {exit: true}));

// catches "kill pid" (for example: nodemon restart)
process.on('SIGUSR1', exitHandler.bind(null, {exit: true}));
process.on('SIGUSR2', exitHandler.bind(null, {exit: true}));

//catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {exit: true}));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62278824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档