eureka简单集群搭建
https://gitee.com/wangxuewaii/codes/zc0lj6emx5dgp2a813ors63
非集群eureka搭建
https://gitee.com/wangxuewaii/codes/zl8to65naewu4y02rsjk937
服务端配置
spring:
application:
name: ek-police
endpoints:
sensitive: false
eureka:
instance:
leaseRenewalIntervalInSeconds: 5
leaseExpirationDurationInSeconds: 60
metadata-map:
company-name: crazyit
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
logging:
level:
com.netflix: DEBUG
注册中心清理失效服务的条件:
1
leaseExpirationDurationInSeconds: 60
这个定义的时间内没收到服务的心跳
2
在60s定时器清理时间到了才会执行清理,要不服务列表是不会被跟新的
元数据的配置
消费者取得元数据
@GetMapping("/meta")
@ResponseBody
public List<ServiceInstance> getMetadata() {
List<ServiceInstance> instances = discoveryClient.getInstances("ek-police");
for(ServiceInstance ins : instances) {
String name = ins.getMetadata().get("company-name");
System.out.println(ins.getPort() + "---" + name);
}
return instances;
}
注册中心的配置
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
server:
enable-self-preservation: false
eviction-interval-timer-in-ms: 5000
服务消费者配置
server:
port: 9000
spring:
application:
name: ek-person
eureka:
client:
registry-fetch-interval-seconds: 90
serviceUrl:
defaultZone: http://localhost:8761/eureka/
logging:
level:
com.netflix: DEBUG