Graceful shutdown means that the service instance can be stopped safely and smoothly without affecting the ongoing business. A Dubbo service may be both a service provider and a service consumer. When the service is stopped:
kill PID
/shutdown
of SpringBoot ActuatorDubbo 3.0 and above supports different types of Java applications, including SpringBoot applications, Spring applications, and non-Spring applications.
Set the graceful shutdown timeout, the default timeout is 10 seconds, if it times out, it will be forced to shut down. This parameter can be configured in the dubbo.properties file, for example: 30 seconds.
# Stop service waiting time, unit: milliseconds
dubbo.service.shutdown.wait=30000
Dubbo uses JDK’s ShutdownHook to complete graceful shutdown, so if the user uses kill -9 PID
and other forced shutdown commands, it will not execute graceful shutdown, and will only execute when kill PID
is passed.
Verify that Dubbo’s ShutdownHook is executed. You can find the keyword in the log file: Run shutdown hook now.
If Spring is used, please upgrade to version 4.2 and above, it is recommended to use version 5 or above
If SpringBoot is used, Dubbo’s ShutdownHook will be executed before SpringBoot’s ShutdownHook, If you use SpringBoot 2.3 and above, it is recommended to use it with SpringBoot’s graceful shutdown, and configure it in the configuration file application.yml:
server:
shutdown: graceful
ApplicationModel.defaultModel().destroy();