Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yangpancode opened this issue Oct 12, 2017 · 4 comments

Comments

@yangpancode
Copy link

yangpancode commented Oct 12, 2017

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

@chickenlj
Copy link
Contributor

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

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

@DayuZhu
Copy link

DayuZhu commented Oct 19, 2017

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

@ralf0131
Copy link
Contributor

Related issue: #1665

@ralf0131
Copy link
Contributor

This has been fixed from 2.6.3 onwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants