Dubbo优雅上下线

1 dubbo优雅上线

监听事件与readiness对齐

暴露预热接口 

1.1 服务注册(服务发现)

NacosAutoServiceRegistration # onApplicationEvent WebServerInitializedEvent

→ NacosAutoServiceRegistration#start()

→ NacosAutoServiceRegistration#register()    

→ NacosServiceRegistry.register(getRegistration())  (spring-cloud注册入口不一样,为第2次注册,入口:DubboServiceRegistrationAutoConfiguration#onDubboBootstrapStarted(registry.register(registration)),但是内部都是调用这个方法)

→ NacosNamingService#registerInstance

→ 增加心跳任务,调用nacos url注册服务实例

1.2 dubbo接口注册

DubboBootStrapAppplicationListener # onApplicationContextEvent  ContextRefreshedContext

→ DubboBootstrap#start

→ DubboBootstrap#exportServices ()

→ DubboBootstrap#exportServices (ServiceConfig sc)

→ ServiceConfig#export()  注册dubbo接口到nacos

(spring-cloud DubboMetadataService注册,入口:DubboServiceRegistrationAutoConfiguration#onDubboBootstrapStarted(attachDubboMetadataServiceMetadata(registration)),但是内部都是调用这个方法,

DubboMetadataService注销入口: DubboMetadataAutoConfiguration#onContextClosed() )

→ ServiceConfig#doExport()  

→ ServiceConfig#doExportUrls()  

→ ServiceConfig#doExportUrlsForProtocol

→  QosProtocolWrapper#export

→  ProtocolFilterWrapper#export

→ ProtocolListenerWrapper#export

→ RegistryPortocol#export

→ ListenerRegistryWrapper#register

→ FailbackRegistry#register

→ NacosRegistry#doRegistry

→ NacosNamingService#registerInstance

→ 增加心跳任务,调用nacos url注册dubbo服务实例

2 dubbo优雅下线

不处理,2.7.X已实现,https://github.com/apache/dubbo/issues/7093 , 是否优雅后面改进。

2.1 服务注销(服务发现)

NacosAutoServiceRegistration#destroy()

→ NacosAutoServiceRegistration#stop()

→ NacosAutoServiceRegistration#deregister()

→ NacosServiceRegistry.deregister(getRegistration())

→ NacosNamingService#deregisterInstance

→ 移除心跳任务,调用nacos url注销服务实例

2.2 dubbo接口注销

DubboBootStrapAppplicationListener #onApplicationContextEvent  ContextClosedEvent

→ DubboShutDownHook.getDubboShutdownHook().run()

→ DubboBootstrap#destroy

→ unexportService 注销dubbo接口

→ ServiceBean#unexport() 

→ ListenerExporterWrapper#unexport() 

→ RegistryProtocol$DestroyableExporter#unexport()

→ RegistryProtocol$ExporterChangeableWrapper#unexport()

→ ListenerRegistryWrapper#unregister

→ FailbackRegistry#unregister

 → NacosRegistry#doUnregister

 → NacosNamingService#deregisterInstance

→ 移除心跳任务,调用nacos url注销dubbo服务实例

最后 DubboShutdownHook.destryAll()

→QosProtocolWrapper#destroy()

→ ProtocolFilterWrapper#destroy()

→ ProtocolListenerWrapper#destroy()

→ DubboProtocol#destroy()

→ (HeaderExchangeServer)server.close(ConfigurationUtils.getServerShutdownTimeout())  dubbo优雅关闭,当连接全部关闭时才关闭服务

shutdownTimeout默认时间:10s

可以通过 dubbo.service.shutdown.wait 来自定义时间,单位 ms

或者dubbo.service.shutdown.wait.seconds来设置,单位 s

发表评论 / Comment

用心评论~