โ€ก๐Ÿ‘ฉโ€๐Ÿ’ป โ€ก/ยบSpring

[MSA] Spring Cloud Netflix Eureka ์„œ๋ฒ„ ๊ตฌ์ถ•

Trudy | ์†ก์—ฐ 2024. 1. 12. 00:07

๐Ÿ“Spring Cloud Netflix Eureka๋ž€?

 

Netflix์—์„œ ๊ฐœ๋ฐœํ•œ ์˜คํ”ˆ ์†Œ์Šค ๊ธฐ๋ฐ˜์˜ ์„œ๋น„์Šค ๋””์Šค์ปค๋ฒ„๋ฆฌ ํ”„๋ ˆ์ž„์›Œํฌ์ด๋‹ค. ์„œ๋น„์Šค ๋””์Šค์ปค๋ฒ„๋ฆฌ๋Š” ๋ถ„์‚ฐ ์‹œ์Šคํ…œ์—์„œ ๊ฐ๊ฐ์˜ ์„œ๋น„์Šค ์ธ์Šคํ„ด์Šค์˜ ์œ„์น˜์™€ ์ƒํƒœ๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ , ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋น„์Šค๋ฅผ ์ฐพ๊ณ  ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ํ•ต์‹ฌ์ ์ธ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค. 

 

https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcChm7C%2FbtrxcakcY90%2FciejD5EKD41t4myHJWuGUk%2Fimg.png

 

๐Ÿ“Service Discovery๋ž€?


๋ถ„์‚ฐ ์‹œ์Šคํ…œ์—์„œ ๊ฐ๊ฐ์˜ ์„œ๋น„์Šค ์ธ์Šคํ„ด์Šค์˜ ์œ„์น˜ ๋ฐ ์ƒํƒœ ์ •๋ณด(IP์ฃผ์†Œ์™€ Port๋ฒˆํ˜ธ)๋ฅผ ๋™์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ณ , ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ด ์„œ๋น„์Šค๋ฅผ ์ฐพ์•„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋•๋Š” ๊ธฐ์ˆ  ๋˜๋Š” ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์˜๋ฏธํ•œ๋‹ค.

์ž‘์€ ๋‹จ์œ„๋กœ ์ชผ๊ฐœ์ ธ์„œ ํ†ต์‹ ํ•ด์•ผํ•˜๋Š” ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค ์•„ํ‚คํ…์ฒ˜์—์„œ ํŠนํžˆ ์ค‘์š”ํ•œ ๊ฐœ๋… ์ค‘ ํ•˜๋‚˜์ด๋‹ค. 


๐Ÿ“Spring Cloud Netflix Eureka ์„œ๋ฒ„ ๊ตฌ์ถ•

Eureka ์„œ๋ฒ„ ๊ตฌ์ถ•์€ ๋น„๊ต์  ๋‹จ์ˆœํ•˜๋‹ค. 

 

1. Eureka ์„œ๋ฒ„ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ 

 

2. pom.xml์— ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€ 

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            <version>3.1.3</version>
        </dependency>

 

3. application.yml์— ์„ค์ • ์ถ”๊ฐ€

server:
  port: 8761

spring:
  application:
    name: discovery-server

#    ์„œ๋ฒ„์— ๋‚ด ์ž์‹ ์„ ๋“ฑ๋กํ•˜์ง€ ๋ง์•„๋ผ. ๋‹ค๋ฅธ ํ”„๋กœ์ ํŠธ๋ฅผ ๋“ฑ๋ก์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„  ์ด๊ฑธ ์ถ”๊ฐ€ํ•˜๋ฉด ๋˜๊ฒ ๋‹ค
# ์ถ”๊ฐ€๊ฐ€ ๋˜๊ฒŒ ํ•˜๋Š” ๊ฒƒ์€ ์„œ๋ฒ„๊ฐ€ ์•„๋‹ˆ๋ผ ํด๋ผ์ด์–ธํŠธ!
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false

     

4. Application.java ํŒŒ์ผ์— @EnableEurekaServer ์ถ”๊ฐ€

package com.example.demo.discovery;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class DiscoveryApplication {
    public static void main(String[] args) {
        SpringApplication.run(DiscoveryApplication.class, args);
    }
}

 

์ด๋ ‡๊ฒŒ๋งŒ ์„ค์ •ํ•˜๋ฉด Eureka ์„œ๋ฒ„ ๊ตฌ์ถ•์€ ๋์ด ๋‚œ๋‹ค!

 

์ด ํ”„๋กœ์ ํŠธ๋ฅผ ์‹คํ–‰์‹œํ‚ค๊ณ  ์„ค์ •ํ•ด๋‘” ํฌํŠธ๋กœ ์ ‘์†ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด Eureka ํ™ˆํŽ˜์ด์ง€๋กœ ์ ‘์† ๊ฐ€๋Šฅํ•˜๋‹ค. 

 

์ด์ œ Eureka์— ์„œ๋น„์Šค๋“ค์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋Š” ์ž‘์—…์„ ํ•˜๋ฉด ๋œ๋‹ค.

์„œ๋น„์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ์œ„ Instance์— ๋ชฉ๋ก์ด ์ถ”๊ฐ€ ๋  ๊ฒƒ์ด๋‹ค. 


๐Ÿ“Eureka์— ๋“ฑ๋กํ•  ์„œ๋น„์Šค ์ถ”๊ฐ€

 

1. pom.xml์— ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€ 

<dependency>
           <groupId>org.springframework.cloud</groupId>
           <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
           <version>3.1.3</version>
           <exclusions>
               <exclusion>
                   <groupId>javax.servlet</groupId>
                   <artifactId>servlet-api</artifactId>
               </exclusion>
           </exclusions>
       </dependency>

 

 2. application.yml์— ์„ค์ • ์ถ”๊ฐ€

server:
  port: 8081

eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaulZone: http://localhost:8761/eureka

 

4. Application.java ํŒŒ์ผ์— @EnableEurekaServer ์ถ”๊ฐ€

@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
public class MemberApplication {

	public static void main(String[] args) {
		SpringApplication.run(MemberApplication.class, args);
	}

}

 


์‹คํ–‰ ๊ฒฐ๊ณผ

 

Eureka ํฌํŠธ๋กœ ์žฌ์ ‘์†์„ ํ•˜๋ฉด ์„ค์ •ํ•ด๋‘” ์„œ๋น„์Šค๋“ค์ด ๋ชฉ๋ก์— ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. 

 


[์ฐธ๊ณ ]

https://yarisong.tistory.com/41

 

Spring Cloud Netflix Eureka - ๊ฐœ๋… ๋ฐ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

ํ•ด๋‹น ๋‚ด์šฉ์€ ์ธํ”„๋Ÿฐ ์ด๋„์›๋‹˜์˜ "Spring Cloud๋กœ ๊ฐœ๋ฐœํ•˜๋Š” ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜(MSA)"๋ฅผ ๋“ฃ๊ณ  ์ •๋ฆฌํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. 1. Spring Cloud Netflix Eureka๋ž€? Netflix Eureka๋ž€? ๋„ทํ”Œ๋ฆญ์Šค์—์„œ MSA๋ฅผ ์œ„ํ•ด Spring Cloud

yarisong.tistory.com