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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值