dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

老的项目组中是用war包的形式运行的应用,如何实现优雅停机

Open yangpancode opened this issue 9 years ago • 4 comments

老的项目组中是用war包的形式运行的应用,改造成jar包的方式有很大的风险,能在不改变原来tomcat部署的方式上实现优雅停机吗?有好的解决方案吗?实现ServletContextListener,并重写contextDestroyed方法再调用ProtocolConfig.destroyAll();不知道是否可行?

yangpancode avatar Oct 12 '17 08:10 yangpancode

实现ServletContextListener,并重写contextDestroyed方法再调用ProtocolConfig.destroyAll();不知道是否可行?

tomcat部署,目前这样操作是可行的。 我们正计划抽象出一个停机操作api,要求使用者遵循固定的停机流程来执行停机,比如使用事先编写好的部署脚本发布服务:先通过telnet命令或http命令通知停机,等待10s后,执行发布操作。

chickenlj avatar Oct 18 '17 14:10 chickenlj

我目前使用 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服务操作成功");
	}

DayuZhu avatar Oct 19 '17 10:10 DayuZhu

Related issue: #1665

ralf0131 avatar Apr 28 '18 09:04 ralf0131

This has been fixed from 2.6.3 onwards.

ralf0131 avatar Jul 16 '18 07:07 ralf0131