dubbo
dubbo copied to clipboard
老的项目组中是用war包的形式运行的应用,如何实现优雅停机
老的项目组中是用war包的形式运行的应用,改造成jar包的方式有很大的风险,能在不改变原来tomcat部署的方式上实现优雅停机吗?有好的解决方案吗?实现ServletContextListener,并重写contextDestroyed方法再调用ProtocolConfig.destroyAll();不知道是否可行?
实现ServletContextListener,并重写contextDestroyed方法再调用ProtocolConfig.destroyAll();不知道是否可行?
tomcat部署,目前这样操作是可行的。 我们正计划抽象出一个停机操作api,要求使用者遵循固定的停机流程来执行停机,比如使用事先编写好的部署脚本发布服务:先通过telnet命令或http命令通知停机,等待10s后,执行发布操作。
我目前使用 http请求 调用ProtocolConfig.destroyAll();
@RequestMapping(value = "/dubboClose")
@ResponseBody
public ReturnObject dubboClose() {
LOG.info("关闭dubbo服务 ");
ApplicationContext context = ServiceLocation.getApplicationContext();
Map<String, ServiceConfig> map = context.getBeansOfType(ServiceConfig.class);
int iSize = map.size();
if (iSize == 0) {
LOG.warn(" 未查询到DUBBO服务 ");
return new ReturnObject(Mnt.RET_CODE_VALUE_NO, "未查询到DUBBO服务");
}
for (Entry<String, ServiceConfig> entry : map.entrySet()) {
LOG.debug("key= " + entry.getKey() + " and value= " + entry.getValue());
ServiceConfig serConfig = entry.getValue();
serConfig.setExport(false);
}
try {
ProtocolConfig.destroyAll();
} catch (Exception ex) {
LOG.warn("关闭dubbo服务失败 ");
return new ReturnObject(Mnt.RET_CODE_VALUE_NO, "关闭dubbo服务操作失败");
}
return new ReturnObject(Mnt.RET_CODE_VALUE_OK, "关闭dubbo服务操作成功");
}
缺点:必须重启容器才能 发布服务 @yangpancode @chickenlj
手动暴露服务
@RequestMapping(value = "/dubboStart")
@ResponseBody
public ReturnObject dubboStart() {
LOG.info("开启dubbo服务 ");
ApplicationContext context = ServiceLocation.getApplicationContext();
Map<String, ServiceConfig> map = context.getBeansOfType(ServiceConfig.class);
int iSize = map.size();
if (iSize == 0) {
LOG.warn(" 未查询到DUBBO服务 ");
return new ReturnObject(Mnt.RET_CODE_VALUE_NO, "未查询到DUBBO服务");
}
for (Entry<String, ServiceConfig> entry : map.entrySet()) {
LOG.debug("key= " + entry.getKey() + " and value= " + entry.getValue());
ServiceConfig serConfig = entry.getValue();
serConfig.setExport(true);
serConfig.export();// 暴露及注册服务
}
return new ReturnObject(Mnt.RET_CODE_VALUE_OK, "开启dubbo服务操作成功");
}
Related issue: #1665
This has been fixed from 2.6.3 onwards.