eureka---服务注册功能

本文探讨了SpringCloud与Eureka的整合,重点关注服务注册功能。核心源码包为`eureka-core`,其中`ApplicationResource`类的`addInstance`方法作为服务注册的入口。`InstanceRegistry`类实现了`ApplicationContextAware`接口,通过`register`方法进行服务注册,该过程在`AbstractInstanceRegistry`的`register`方法中得到具体实现,并涉及到了心跳续约相关的时间戳记录。
摘要由CSDN通过智能技术生成

org.springframework.cloud.netflix.eureka.server是SpringCloud和Eureka整合的源码包
com.netflix.eureka:eureka-core就是eureka的核心源码包(功能实现)
在resours目录下的ApplicationResource就是服务注册功能(对应某一个微服务实例)
类ApplicationResource下的addInstance就是服务注册功能的入口:

@POST
    @Consumes({
   "application/json", "application/xml"})
    public Response addInstance(InstanceInfo info, @HeaderParam("x-netflix-discovery-replication") String isReplication) {
   
        logger.debug("Registering instance {} (replication={})", info.getId(), isReplication);
        //都是参数校验
        if (this.isBlank(info.getId())) {
   
            return Response.status(400).entity("Missing instanceId").build();
        } else if (this.isBlank(info.getHostName())) {
   
            return Response.status(400).entity("Missing hostname").build();
        } else if (this.isBlank(info.getIPAddr())) {
   
            return Response.status(400).entity("Missing ip address").build();
        } else if (this.isBlank(info.getAppName())) {
   
            return Response.status(400).entity("Missing appName").build();
        } else if (!this.appName.equals(info.getAppName())) {
   
            return Response.status(400).entity("Mismatched appName, expecting " + this.appName + " but was " + info.getAppName()).build();
        } else if (info.getDataCenterInfo() == null) {
   
            return Response.status(400).entity("M
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值