Eureka
Eureka Server注册中心
简单的高可用,开启3个eureka 相互注册到对方上。
pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
yml (这里,的另外2个eureka 都填写对方的端口)
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/,http://localhost:8763/eureka/
register-with-eureka: false #不把自己注册到client上
server:
# 自我保护机制,一个服务开关太过频繁,注册中心就一段时间内直接认为你是在的,开发环境下设置成false(实际环境要打开),防止服务挂掉,注册还在
enable-self-preservation: false
spring:
application:
name: eureka
server:
port: 8762
@SpringBootApplication
@EnableEurekaServer
public class Eureka1Application {
public static void main(String[] args) {
SpringApplication.run(Eureka1Application.class, args);
}
}
Eureka Client 服务注册
pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
yml
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/,http://localhost:8763/eureka/
spring:
application:
name: client-user # 服务名称
启动类
@SpringBootApplication
@EnableDiscoverClient
public class Eureka1Application {
public static void main(String[] args) {
SpringApplication.run(Eureka1Application.class, args);
}
}
完整pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.