eureka server集群相关源码分析
前面的文章分别介绍了服务启动、注册、下线、故障和自我保护机制等原理,这里就开始介绍集群相关的东西。
上一篇文章,我们分析了eureka server的启动流程,这一篇来分析一下eureka client的启动流程。我们先要找到启动入口在哪里。在eureka-examples里,有一个ExampleEurekaClient的测试类。要执行这个类,首先需要复制一段代码,设置一些基础属性,这是从eureka-server的单元测试里复制过来的:
1 | /** |
如果要阅读一个开源框架的源码,我们应该从什么地方入手。首先应该想到的是,从框架启动的入口入手,比如Eureka,肯定是从Eureka服务本身启动的入口开始。或者我们也可以从框架的单元测试开始看,因为单元测试都包含了框架的核心流程和功能。所以我们通过这2个入口,可以通过打断点执行的方式阅读代码的逻辑。下面我将开始学习Eureka的源码,我将基于https://github.com/Netflix/eureka.git 的v1.7.2分支进行阅读,因为我目前所用的SpringCloud引入的就是这个版本。
默认情况下,SpringBoot会引入spring-boot-starter-logging,也就是logback的日志实现。
在resources下新建logback-spring.xml
可以自定义日志配置,这是约定的文件名字。
在spring-boot-starter-logging-2.1.4.RELEASE这个依赖中,在/org/springframework/boot/logging/logback/base.xml位置可以找到SpringBoot提供的一个默认配置,基于这个配置进行自定义
1 | <?xml version="1.0" encoding="utf-8" ?> |
Class that can be used to bootstrap and launch a Spring application from a Java main method. By default class will perform the following steps to bootstrap your application:
微服务学习笔记
https://spring.io/projects/spring-boot#learn
要创建一个Spring Boot项目,可以去https://start.spring.io/,一键创建。
依赖中加入Web,然后点击Generate Project
,就会下载一个压缩包。
微服务学习笔记
https://martinfowler.com/articles/microservices.html
“Microservices” - yet another new term on the crowded streets of software architecture. Although our natural inclination is to pass such things by with a contemptuous glance, this bit of terminology describes a style of software systems that we are finding more and more appealing. We’ve seen many projects use this style in the last few years, and results so far have been positive, so much so that for many of our colleagues this is becoming the default style for building enterprise applications. Sadly, however, there’s not much information that outlines what the microservice style is and how to do it.