Eureka 는 자가 등록, 동적 발견 및 부하 분산을 담당하며 위의 서비스 디스커버리 패턴을 구현할 수 있도록 도와준다.
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2023.0.0")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
@SpringBootApplication
@EnableEurekaServer
class EurekaApplication
fun main(args: Array<String>) {
runApplication<EurekaApplication>(*args)
}
spring:
application:
name: eureka-server
profiles:
active: dev
server:
port: 8761
eureka:
server:
enable-self-preservation: true
instance:
hostname: api-discovery.com
secure-port: ${server.port}
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://api-discovery.com:8761/eureka
disable-delta: true
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
@SpringBootApplication
@EnableEurekaClient
public class EurekaclientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaclientApplication.class, args);
}
}
server:
port: 8080
spring:
application:
name: user-Service
profiles:
active: dev
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka
동록됫다는 로그를 확인할 수 있다.
2023-06-26 17:50:02.551 INFO 3560 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8080
2023-06-26 17:50:02.626 INFO 3560 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_USER-SERVICE/host.docker.internal:user-Service:8080 - registration status: 204
2023-06-26 17:50:02.788 INFO 3560 --- [ main] git.io.apiuser.ApiUserApplicationKt : Started ApiUserApplicationKt in 4.559 seconds (JVM running for 5.463)