이 글은 Spring Cloud로 마이크로서비스 아키텍처(MSA)를 처음부터 구성하는 실습의 1부다. JDK·Maven·STS 개발환경 준비부터, 서비스 디스커버리의 핵심인 Eureka 서버와 여기에 등록되는 Eureka 클라이언트 여러 개를 띄우는 것까지 다룬다. 실제 라우팅·로드밸런싱은 2부에서 이어진다.
Spring Cloud를 활용한 MSA 설치 및 구성-1


spring cloud
https://spring.io/projects/spring-cloud
Spring Cloud
Spring Cloud is an umbrella project consisting of independent projects with, in principle, different release cadences. To manage the portfolio a BOM (Bill of Materials) is published with a curated set of dependencies on the individual project. Go here to r
spring.io
spring cloud vs kubernetes

-> jdk-11.0.15.1_windows-x64_bin.exe
-> spring-tool-suite-4-4.15.1.RELEASE-e4.24.0-win32.win32.x86_64.self-extracting.jar
-> apache-maven-3.8.6-bin.zip
jdk 11 설치
maven 압축해제
1. 개발 환경 준비 (JDK 11 · Maven · STS)
JAVA_HOME C:\Program Files\Java\jdk-11.0.15.1
Path %JAVA_HOME%\bin
MAVEN_HOME C:\apache-maven-3.8.6
Path %MAVEN_HOME%\bin
명령창 테스트
java -version
javac -version
mvn





캐시경로
C:\Users\HPE\.m2\repository













https://projectlombok.org/download
java -jar lombok.jar을 STS에 설치

http://localhost:8080/v1/organization/optimaGrowth/license/2313202

eureka server







2. Eureka 서버 설정
서비스들의 위치를 등록·조회하는 서비스 디스커버리 서버입니다. 자기 자신은 등록/조회하지 않도록 register/fetch를 false로 둡니다. (기본 포트 8761)
spring.application.name=MyServer
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
server.port=8761




3. Eureka 클라이언트 설정 (다중 인스턴스)
Eureka 서버에 자신을 등록하는 서비스들입니다. MyClient1~3을 서로 다른 포트로 띄워, 하나의 디스커버리 서버에 여러 서비스가 모이는 구조를 확인합니다. 각 클라이언트는 @EnableEurekaClient로 등록되고 defaultZone으로 서버 주소를 가리킵니다.
spring.application.name=MyClient1
server.port=8081
eureka.instance.prefer-ip-address=true
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
eureka.client.fetch-registry=true
eureka.client.register-with-eureka=true

package com.test.myclient1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@EnableEurekaClient
@RestController
public class MyClient1Application {
public static void main(String[] args) {
SpringApplication.run(MyClient1Application.class, args);
}
@RequestMapping(value="/")
public String hello() {
return "Eureka Client Application";
}
}



spring.application.name=MyClient2
server.port=8082
eureka.instance.prefer-ip-address=true
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
eureka.client.fetch-registry=true
eureka.client.register-with-eureka=true

spring.application.name=MyClient3
server.port=8083
eureka.instance.prefer-ip-address=true
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
eureka.client.fetch-registry=true
eureka.client.register-with-eureka=true

package com.test.myclient3;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.test.myclient3.MyClient3Application;
@SpringBootApplication
@EnableEurekaClient
@RestController
public class MyClient3Application {
public static void main(String[] args) {
SpringApplication.run(MyClient3Application.class, args);
}
@RequestMapping(value="/")
public String hello() {
return "Eureka Client Application #3";
}
}


마치며
1부에서는 MSA의 뼈대인 서비스 디스커버리를 세웠습니다 — Eureka 서버 하나에 여러 클라이언트가 자동 등록되어, 각 서비스가 IP·포트를 하드코딩하지 않고도 서로를 찾을 수 있게 됩니다. 이 위에 게이트웨이 라우팅과 로드밸런싱을 얹는 과정은 MSA 설치 및 구성-2에서 이어집니다.
'푸닥거리' 카테고리의 다른 글
| .NET TLS versioncompilation targetFramework httpRuntime targetFramework (0) | 2022.08.02 |
|---|---|
| Spring Cloud를 활용한 MSA 설치 및 구성-2 (0) | 2022.07.24 |
| 교육훈련기관 과정운영 점검을 위한 모니터링 (0) | 2022.07.21 |
| OOP(Object-Oriented Programming) 의 SOLID 원칙 (0) | 2022.07.10 |
| 아키텍처 패턴(Architecture Patterns), 디자인 패턴(Design Pattern) (0) | 2022.07.09 |
댓글