Eureka setting

Eureka ๋Š” ์ž๊ฐ€ ๋“ฑ๋ก, ๋™์  ๋ฐœ๊ฒฌ ๋ฐ ๋ถ€ํ•˜ ๋ถ„์‚ฐ์„ ๋‹ด๋‹นํ•˜๋ฉฐ ์œ„์˜ ์„œ๋น„์Šค ๋””์Šค์ปค๋ฒ„๋ฆฌ ํŒจํ„ด์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ค€๋‹ค.

Eureka Server
Eureka Client

๋ชจ๋“  ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค๊ฐ€ ์ž์‹ ์˜ ๊ฐ€์šฉ์„ฑ์„ ๋“ฑ๋กํ•˜๋Š” ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ

๋“ฑ๋ก๋œ ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค๋ฅผ ํ˜ธ์ถœํ•ด์„œ ์‚ฌ์šฉํ•  ๋•Œ Eureka Client ๋ฅผ ์ด์šฉํ•ด์„œ ํ•„์š”ํ•œ ์„œ๋น„์Šค๋ฅผ ๋ฐœ๊ฒฌ

๋“ฑ๋ก๋˜๋Š” ์ •๋ณด๋Š” ์„œ๋น„์Šค ID์™€ URL ์ด ํฌํ•จ๋˜๋Š”๋ฐ, ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค๋Š” Eureka Client ๋ฅผ ์ด์šฉํ•ด์„œ ์ด ์ •๋ณด๋ฅผ Eureka Server ์— ๋“ฑ๋ก

Eureka Server ๋Š” Eureka Server ์ธ ๋™์‹œ์— ์„œ๋กœ์˜ ์ƒํƒœ๋ฅผ ๋™๊ธฐํ™”ํ•˜๊ธฐ ์„œ๋กœ๋ฅผ ๋ฐ”๋ผ๋ณด๋Š” Eureka Client ์ด๊ธฐ๋„ ํ•œ๋‹ค ์ด ์ ์€ Eureka Server ์˜ ๊ณ ๊ฐ€์šฉ์„ฑ์„ ์œ„ํ•ด ์—ฌ๋Ÿฌ ๋Œ€์˜ Eureka Server ์šด์˜ ์‹œ ์œ ์šฉ

START EUREKA

SERVER SETTING

์˜์กด์„ฑ ์ถ”๊ฐ€ springCloudVersion ๋ฒ„์ „ ์ฐธ๊ณ 

build.gradle
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}"
  }
}

์„ค์ • ํ™œ์„ฑํ™”

mainApplication.kt
@SpringBootApplication
@EnableEurekaServer
class EurekaApplication

fun main(args: Array<String>) {
	runApplication<EurekaApplication>(*args)
}

์„ค์ • ํŒŒ์ผ

application.yml
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

์„ ์ง€์ •ํ•ด ์ค€๋’ค ์‹คํ–‰ํ•˜๋ฉด

CLIENT SETTING

์˜์กด์„ฑ ์ถ”๊ฐ€

build.gradle
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)

Last updated

Was this helpful?