首页  

Eureka源码要点     所属分类 springcloud 浏览量 887
com.netflix.discovery.DiscoveryClient 
CacheRefreshThread
HeartbeatThread

服务注册 register() 

服务下线 shutdown()
unregister()


// 服务注册 register
httpResponse = eurekaTransport.registrationClient.register(instanceInfo);
// 心跳 renew
httpResponse = eurekaTransport.registrationClient.sendHeartBeat(instanceInfo.getAppName(), instanceInfo.getId(), instanceInfo, null);
// 服务下线 cancel
EurekaHttpResponse<Void> httpResponse = eurekaTransport.registrationClient.cancel(instanceInfo.getAppName(), instanceInfo.getId());

调用 AbstractJerseyEurekaHttpClient  实现 EurekaHttpClient接口




Eureka Server 维护服务注册信息 处理EurekaClient的register renew cancel请求 EurekaServer 节点之间的数据复制同步 spring-cloud-netflix-eureka-server-x.x.x.RELEASE META-INF/spring.factories org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration EurekaController dashboard页面控制器 PeerAwareInstanceRegistry 处理EurekaClient的register renew cancel等请求 PeerEurekaNodes 处理EurekaServer多节点同步 ApplicationResource InstanceResource com.netflix.eureka.resources.ApplicationResource.addInstance(InstanceInfo, String) @POST @Consumes({"application/json", "application/xml"}) public Response addInstance(InstanceInfo info,@HeaderParam(PeerEurekaNode.HEADER_REPLICATION) String isReplication) PeerAwareInstanceRegistryImpl public void register(final InstanceInfo info, final boolean isReplication) { int leaseDuration = Lease.DEFAULT_DURATION_IN_SECS; if (info.getLeaseInfo() != null && info.getLeaseInfo().getDurationInSecs() > 0) { leaseDuration = info.getLeaseInfo().getDurationInSecs(); } // 调用AbstractInstanceRegistry父类的方法 super.register(info, leaseDuration, isReplication); // 向其他Eureka Server节点同步注册信息 replicateToPeers(Action.Register, info.getAppName(), info.getId(), info, null, isReplication); } Replicates all eureka actions to peer eureka nodes except for replication traffic to this node. private void replicateToPeers(Action action, String appName, String id, InstanceInfo info /* optional */, InstanceStatus newStatus /* optional */, boolean isReplication) public enum Action { Heartbeat, Register, Cancel, StatusUpdate, DeleteStatusOverride public class PeerAwareInstanceRegistryImpl extends AbstractInstanceRegistry implements PeerAwareInstanceRegistry 注册表信息 public abstract class AbstractInstanceRegistry implements InstanceRegistry { private static final Logger logger = LoggerFactory.getLogger(AbstractInstanceRegistry.class); private static final String[] EMPTY_STR_ARRAY = new String[0]; private final ConcurrentHashMap<String, Map<String, Lease<InstanceInfo>>> registry = new ConcurrentHashMap<String, Map<String, Lease<InstanceInfo>>>();

上一篇     下一篇
SpringCloud全家桶简介

Feign Ribbon Hystrix

eureka工作原理简介

Hystrix实例

SpringMVC @ControllerAdvice 注解

springboot读取配置的几种方式