You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Eureka Client 적용하기 - Product 서버

1. [product] bulid.gradle

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

2. [product] ProductApplication : @EnableEurekaClient

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

3. [product] application.yml

application.yml
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

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

2. [display] DisplayApplication : @EnableEurekaClient

ProductApplication
@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

application.yml
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


  • No labels