eureka

정리공간·2022년 6월 10일
0

같은 webapp의 인스턴스가 여러개 있을 경우 로드밸런싱 기능
인스턴스의 접속정보를 관리해주므로 접속정보가 추가/변경될때마다 gateway에 ip,port정보를 알 필요 없음
모든 app을 자바로 구현할 때 유용하고 k8s를 구축하면 자바에 종속적이지 않고 필요없어짐

eureka server

pom.xml

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

application.java

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

application.yml

server:
  port: 8761
spring:
  application:
    name: discoveryservice
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false

localhost:8761 접속

eureka client

pom.xml

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

application.java

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

application.yml

server:
  port: 0
spring:
  application:
    name: order-service
eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://localhost:8761/eureka
  instance:
    instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}

eurekaClient 구동 후 localhost:8761접속하여 확인

0개의 댓글