๐Spring Cloud Netflix Eureka๋?
Netflix์์ ๊ฐ๋ฐํ ์คํ ์์ค ๊ธฐ๋ฐ์ ์๋น์ค ๋์ค์ปค๋ฒ๋ฆฌ ํ๋ ์์ํฌ์ด๋ค. ์๋น์ค ๋์ค์ปค๋ฒ๋ฆฌ๋ ๋ถ์ฐ ์์คํ ์์ ๊ฐ๊ฐ์ ์๋น์ค ์ธ์คํด์ค์ ์์น์ ์ํ๋ฅผ ๊ด๋ฆฌํ๊ณ , ํด๋ผ์ด์ธํธ๊ฐ ์๋น์ค๋ฅผ ์ฐพ๊ณ ํต์ ํ ์ ์๋๋ก ๋์์ฃผ๋ ํต์ฌ์ ์ธ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ค.

๐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
'โก๐ฉโ๐ป โก > ยบSpring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Postman] form-data๋ก Multipart๋ JSON ๋์์ ๋ณด๋ด๊ธฐ (0) | 2024.06.14 |
---|---|
[MSA] Resilience4j | ์ํท ๋ธ๋ ์ด์ปค ๊ฐ๋ ๋ฐ ์ ์ฉ (0) | 2024.01.12 |
[MSA] Apache Kafka (๋ถ์ฐ ๋ฉ์์ง ์์คํ ) ์๋ฒ ๊ตฌ์ถ (0) | 2024.01.11 |
[Spring] ํ๋ก์ ํธ ๋ฐฐํฌ | nginx proxy ์๋ฒ์ spring ์ฐ๋ (0) | 2024.01.09 |
์ฐ๊ด๊ด๊ณ ์ธ๋ํค ์ ์ฅํ ๋ Entity๋ก ํด์ฃผ๋ ์ด์ (1) | 2024.01.03 |