4、SpringCloud之Gateway事件发布机制

Gateway中涉及三大块知识包括Netty、响应式框架Reactor以及Gateway。虽然Gateway集成SpringBoot、SpringCloud等微服务架构,但是利用Netty取代了传统Web框架SpringMvc,所以其启动流程会有很大的差异。本文主要结合启动流程分析Gateway中涉及的事件发布机制,从而对Gateway中动态路由功能有更加直观的感受。

Gateway中触发事件发布机制的核心类为AnnotationConfigReactiveWebServerApplicationContext。在启动类 ConfigurableApplicationContext#run 中完成初始化。

在这里插入图片描述
如图所示:ApplicationContext核心类同时也是一个发布者。

1、EurekaClientAutoConfiguration

借助 EurekaClientAutoConfiguration 心跳机制完成 AnnotationConfigReactiveWebServerApplicationContext发布者事件的发布。

public EurekaClient eurekaClient(ApplicationInfoManager manager,
				EurekaClientConfig config, EurekaInstanceConfig instance,
				@Autowired(required = false) HealthCheckHandler healthCheckHandler) {
   
	// content:AnnotationConfigReactiveWebServerApplicationContext
	CloudEurekaClient cloudEurekaClient = new CloudEurekaClient(appManager,config, this.optionalArgs, this.context);
}

1.1、CloudEurekaClient

public class CloudEurekaClient extends DiscoveryClient {
   

	public CloudEurekaClient(ApplicationInfoManager applicationInfoManager,
			EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs<?> args,
			ApplicationEventPublisher publisher) {
   
		super(applicationInfoManager, config, args);//初始化 DiscoveryClient
		this.applicationInfoManager = applicationInfoManager;
		this.publisher = publisher;// AnnotationConfigReactiveWebServerApplicationContext
		this.eurekaTransportField = ReflectionUtils.findField(DiscoveryClient.class,
				"eurekaTransport");
		ReflectionUtils.makeAccessible(this.eurekaTransportField);
	}

	protected void onCacheRefreshed() {
   
		super.onCacheRefreshed();
		if (this
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值