Spring Cloud - Eureka服务注册
之前分析过Spring Cloud的Eureka服务发现, 今天分析一下服务注册.
配置
BootstrapConfiguration
EurekaDiscoveryClientConfigServiceBootstrapConfiguration
spring-cloud-config环境中使用的配置
引入EurekaDiscoveryClientConfiguration
和EurekaClientAutoConfiguration
EurekaDiscoveryClientConfiguration
- 在spring-cloud中(通过是否存在RefreshScopeRefreshedEvent.class判断), 添加
RefreshScopeRefreshedEvent
的listener. 收到事件后重新注册实例. - 在
eureka.client.healthcheck.enabled
设置为true时, 注册EurekaHealthCheckHandler
bean.EurekaHealthCheckHandler
负责将应用状态映射为实例状态InstanceStatus
.
EurekaClientAutoConfiguration
支持spring-cloud和非spring-cloud环境, 在spring-cloud环境中, 下面两个bean要使用@RefreshScope
标注
- 实例化
EurekaClient
bean, 在spring-cloud中使用实现类CloudEurekaClient
. - 使用
EurekaInstanceConfig
实例, 实例化ApplicationInfoManager
bean