EurekaServer端--集群同步

本文探讨了Eureka Server集群同步的问题,包括集群同步时的循环注册如何避免以及为何需要判断请求是否来自集群同步。通过分析`EurekaServerBootstrap`和`PeerAwareInstanceRegistryImpl`类,揭示了Eureka在集群同步中的自我保护机制和全量、增量同步策略。
摘要由CSDN通过智能技术生成

在写@EurekaServer注解的博客时,有写道org.springframework.cloud.netflix.eureka.server是SpringCloud和Eureka整合的源码包,Eureka的初始化工作也在这个里面完成,当然也包括集群同步!!!

这是我当时没看之前的疑惑之处!!!
问题1:集群同步时,会不会出现比如server1将请求发给server2,server2将请求发给serve3,server1也将请求发给server3,这种互相同步的情况?解决办法?
问题2:前面博客有写道isReplication是用来判断是否来自于集群同步的,为什么要去判断这个请求是否来自于集群同步?
问题记录在这,最后会在总结中写出我理解答案!!!
在这里插入图片描述
通过spring.factories里面的配置路径进入EurekaServerAutoConfiguration类,
在这里插入图片描述
这个类中通过@Import({EurekaServerInitializerConfiguration.class})引入了Eureka的初始化配置类,这个类主要做了俩件事情
(1)初始化Eureka的配置
(2)初始化Eureka Context的配置(集群注册同步信息、启动一些定时器(其中就包括服务剔除和自我保护的定时器)等)

public void start() {
   
        (new Thread(new Runnable() {
   
            public void run() {
   
                try {
   
                //初始化Eureka Context
                    EurekaServerInitializerConfiguration.this.eurekaServerBootstrap.contextInitialized(EurekaServerInitializerConfiguration.this.servletContext);
                    EurekaServerInitializerConfiguration.log.info("Started Eureka Server");
                    EurekaServerInitializerConfiguration.this.publish(new EurekaRegistryAvailableEvent(EurekaServerInitializerConfiguration.this.getEurekaServerConfig()));
                    EurekaServerInitializerConfiguration.this.running = true;
                    EurekaServerInitializerConfiguration.this.publish(new EurekaServerStartedEvent(EurekaServerInitializerConfiguration.this.getEurekaServerConfig()));
                } catch (Exception var2) {
   
                    EurekaServerInitializerConfiguration.log.error("Could not initialize Eureka servlet context", var2);
                }

            }
        })).start();
    }

进入eurekaServerBootstrap类的contextInitialized方法

public void contextInitialized(ServletContext context) {
   
    try {
   
        this.initEurekaEnvironment();
        //这里就是在初始化Eureka Context
        this.initEurekaServerContext();
        context.setAttribute(EurekaServerContext.class.getName(), this.serverContext);
    } catch (Throwable var3) {
   
        log.error("Cannot bootstrap eureka server :", var3);
        throw new RuntimeException("Cannot bootstrap eureka server :", var3);
    }
}
protected void initEurekaServerContext() throws Exception {
   
    JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), 10000
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值