Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info
iconfalse

Table of Contents

사전조건

Info
iconfalse

Eureka Server (Registry) 만들기

Code Block
git checkout tags/step-4-eureka-completed -b step-4-eureka-completed

Eureka Client 적용하기 - Product 서버

1. [product] bulid.gradle

Code Block
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')

2. [product] ProductApplication : @EnableEurekaClient

Code Block
languagejava
titleProductApplication
linenumberstrue
@SpringBootApplication
@EnableEurekaClient
public class ProductApplication {
    public static void main(String[] args) {
        SpringApplication.run(ProductApplication.class);
    }
}

3. [product] application.yml

Code Block
languageyml
titleapplication.yml
linenumberstrue
server:
  port: 8082

spring:
  application:
    name: product

eureka:
  instance:
    prefer-ip-address: true
  client:
    service-url:
      defaultZone: http://127.0.0.1:8761/eureka  # default address

Eureka Client 적용하기 - Display 서버

1. [display] bulid.gradle

Code Block
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')

2. [display] DisplayApplication : @EnableEurekaClient

Code Block
languagejava
titleProductApplication
linenumberstrue
@SpringBootApplication
@EnableCircuitBreaker
@EnableEurekaClient
public class DisplayApplication {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

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

3. [product] application.yml

Code Block
languageyml
titleapplication.yml
linenumberstrue
server:
  port: 8081

spring:
  application:
    name: display

hystrix:
  command:
    productInfo:    # command key. use 'default' for global setting.
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 3000
      circuitBreaker:
        requestVolumeThreshold: 1   # Minimum number of request to calculate circuit breaker's health. default 20
        errorThresholdPercentage: 50 # Error percentage to open circuit. default 50

product:
  ribbon:
    # listOfServers: localhost:8082,localhost:7777  #서버 주소는 Eureka Server에서 가져와라!
    MaxAutoRetries: 0
    MaxAutoRetriesNextServer: 1

eureka:
  instance:
    prefer-ip-address: true
  client:
    service-url:
      defaultZone: http://127.0.0.1:8761/eureka  # default address

...

실행결과

Info
iconfalse

Image Added

Image Added

Image Added