헤르메스 LIFE

[Spring Cloud Netflix] Eureka Client 샘플 본문

Spring Boot Framework

[Spring Cloud Netflix] Eureka Client 샘플

헤르메스의날개 2024. 3. 14. 00:01
728x90

https://github.com/hermeswing/EurekaClient

 

GitHub - hermeswing/EurekaClient

Contribute to hermeswing/EurekaClient development by creating an account on GitHub.

github.com


개발환경

JDK : Zulu JDK 17.0.10

SpringBoot 3.2.3

SpringBoot Eureka Client ( 현재 최신 버전 :4.1.0 )

Build Tools : Gradle


 

1. 프로젝트 생성

2. Eureka Client

- 아래의 소스가 전부 입니다. ( 의외로 엄청 간단합니다. )

build.gradle

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.2.3'
	id 'io.spring.dependency-management' version '1.1.4'
}

group = 'octopus'
version = '0.0.1-SNAPSHOT'

java {
	sourceCompatibility = '17'
}

repositories {
	mavenCentral()
}

ext {
	set('springCloudVersion', "2023.0.0")         // 스프링 클라우드 버전
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

dependencyManagement {
	imports {
		mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
	}
}

tasks.named('test') {
	useJUnitPlatform()
}

EurekaClientApplication.java

package octopus;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableDiscoveryClient
// @EnableEurekaClient        // Spring Cloud Version 2022.0 이상의 경우 사용할 수 없음.
public class EurekaClientApplication {

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

}

application.yml

spring:
  application:
    name: EurekaClient

server:
  port: 9191

eureka:
  client:
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defaultZone: http://localhost:8761/eureka/         #Eureka Server 경로
  instance:
    hostname: localhost

3. 실행 ( http://localhost:8761 )

Eureka Server에 접속된 Client의 목록 보여집니다.

30초에 한 번씩 Heatbeat를 체크할 것입니다. ( Default )


4. Gradle Jar 빌드

- /build/libs 폴더에 Jar 파일이 생성됩니다.

IntelliJ 에서의 빌드 ( Tasks > build > bootJar )

Linux 에서의 빌드

$ source ./gradlew bootJar

$ . ./gradlew bootJar

5. jar 실행

-D 옵션을 사용해서 여러개의 Client를 띄울 수 있습니다.

# java -jar -Dserver.port=9001 [jar 파일경로]/[jar파일]
$ java -jar -Dserver.port=9001 ./build/libs/EurekaClient-0.0.1-SNAPSHOT.jar
# Java version 오류
$ java -jar EurekaClient-0.0.1-SNAPSHOT.jar
Error: LinkageError occurred while loading main class org.springframework.boot.loader.launch.JarLauncher
        java.lang.UnsupportedClassVersionError: org/springframework/boot/loader/launch/JarLauncher has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

 


https://hermeslog.tistory.com/742

 

[SDKMAN] JDK 버전을 관리하는 Tool 이라고 합니다.

JDK의 버전을 관리해주는 Tool 있다고 합니다. SDKMAN https://sdkman.io/ Home - SDKMAN! the Software Development Kit Manager SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. sdkm

hermeslog.tistory.com

https://hermeslog.tistory.com/755

 

[Spring Cloud Netflix] Eureka Server 개발

https://github.com/hermeswing/EureakServer GitHub - hermeswing/EureakServer: Spring Eureka Server Spring Eureka Server. Contribute to hermeswing/EureakServer development by creating an account on GitHub. github.com 개발환경 JDK : Zulu JDK 17.0.10 Sprin

hermeslog.tistory.com

https://github.com/Jimoou/springboot-microservices?tab=readme-ov-file

 

GitHub - Jimoou/springboot-microservices: Understand and implement typical MSA structures.

Understand and implement typical MSA structures. Contribute to Jimoou/springboot-microservices development by creating an account on GitHub.

github.com

 

728x90