You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by cr...@apache.org on 2022/06/17 04:02:50 UTC

[dubbo-website] branch master updated: Improve documentation for graceful shutdown feature of Dubbo3 (#1104)

This is an automated email from the ASF dual-hosted git repository.

crazyhzm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-website.git


The following commit(s) were added to refs/heads/master by this push:
     new cd8b02fb12 Improve documentation for graceful shutdown feature of Dubbo3 (#1104)
cd8b02fb12 is described below

commit cd8b02fb12713368755a7554b88661380d92f1fb
Author: cdfive <31...@users.noreply.github.com>
AuthorDate: Fri Jun 17 12:02:45 2022 +0800

    Improve documentation for graceful shutdown feature of Dubbo3 (#1104)
    
    * Improve documentation for graceful shutdown feature of Dubbo3
    
    * Improve document format
    
    * Fix typo and markdown format
---
 .../others/graceful-shutdown.md                    | 49 +++++++++++++---------
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/content/zh/docs3-building/java-sdk/advanced-features-and-usage/others/graceful-shutdown.md b/content/zh/docs3-building/java-sdk/advanced-features-and-usage/others/graceful-shutdown.md
index afdae3810d..e34173c3a6 100644
--- a/content/zh/docs3-building/java-sdk/advanced-features-and-usage/others/graceful-shutdown.md
+++ b/content/zh/docs3-building/java-sdk/advanced-features-and-usage/others/graceful-shutdown.md
@@ -6,36 +6,45 @@ weight: 2
 description: "让 Dubbo 服务完成优雅停机"
 ---
 
-Dubbo 是通过 JDK 的 ShutdownHook 来完成优雅停机的,所以如果用户使用 `kill -9 PID` 等强制关闭指令,是不会执行优雅停机的,只有通过 `kill PID` 时,才会执行。
+## 特性说明
 
-## 原理
+优雅停机是指服务实例能安全平稳的停止,对进行中的业务不产生影响。
+一个Dubbo服务可能既作为服务提供者,又是服务消费者,当服务停止时:
+1. 消费者不会再请求已停止的服务实例
+2. 该服务实例正在处理的请求能正常处理完成
 
-服务提供方
+## 使用场景
 
-* 停止时,先标记为不接收新请求,新请求过来时直接报错,让客户端重试其它机器。
-* 然后,检测线程池中的线程是否正在运行,如果有,等待所有线程执行完成,除非超时,则强制关闭。
+1. 通过 `kill PID` 停止服务
+2. 通过 SpringBoot Actuator 的 `/shutdown` 停止服务
 
-服务消费方
+Dubbo 3.0 及以上版本支持不同类型的Java应用,包括 SpringBoot 应用、 Spring 应用、非 Spring 应用。
 
-* 停止时,不再发起新的调用请求,所有新的调用在客户端即报错。
-* 然后,检测有没有请求的响应还没有返回,等待响应返回,除非超时,则强制关闭。
-
-## 设置方式
+## 使用方式
 
 设置优雅停机超时时间,缺省超时时间是 10 秒,如果超时则强制关闭。
-
+该参数可在 dubbo.properties 文件里配置,例如:配置为 30 秒。
 ```properties
-# dubbo.properties
-dubbo.service.shutdown.wait=15000
+# 停止服务等待时间,单位:毫秒
+dubbo.service.shutdown.wait=30000
 ```
 
-如果 ShutdownHook 不能生效,可以自行调用:
+## 注意事项
 
-```java
-DubboShutdownHook.destroyAll();
-```
+1. Dubbo 是通过 JDK 的 ShutdownHook 来完成优雅停机的,所以如果用户使用 `kill -9 PID` 等强制关闭指令,是不会执行优雅停机的,只有通过 `kill PID` 时,才会执行。
 
-{{% alert title="建议" color="primary" %}}
-使用 tomcat 等容器部署的场景,建议通过扩展 ContextListener 等自行调用以下代码实现优雅停机
-{{% /alert %}}
+2. 验证是否执行了 Dubbo 的 ShutdownHook 可在日志文件中查找关键字:`Run shutdown hook now.`
 
+3. 如果使用了 Spring,请升级 4.2 及以上版本,建议使用 5 以上版本
+
+4. 如果使用了 SpringBoot,Dubbo 的 ShutdownHook 会在 SpringBoot 的 ShutdownHook 之前执行,
+如果使用 SpringBoot 2.3及以上版本,建议配合 SpringBoot 的优雅停机使用,在配置文件 applicaion.yml 中配置:
+```yml
+server:
+  shutdown: graceful
+```
+
+5. 如果 ShutdownHook 不能生效,可根据具体场景自行调用:
+```java
+ApplicationModel.defaultModel().destroy();
+```
\ No newline at end of file