add circuit breaker

This commit is contained in:
kimscott
2020-02-06 17:17:15 +09:00
parent da89746eeb
commit 5a126c4689
5 changed files with 16 additions and 6 deletions

View File

@@ -84,6 +84,11 @@
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<!-- Add Stackdriver Trace Starter --> <!-- Add Stackdriver Trace Starter -->
<!-- <dependency>--> <!-- <dependency>-->

View File

@@ -4,12 +4,14 @@ import com.example.template.config.kafka.KafkaProcessor;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@SpringBootApplication @SpringBootApplication
@EnableBinding(KafkaProcessor.class) @EnableBinding(KafkaProcessor.class)
@EnableCircuitBreaker @EnableCircuitBreaker
@EnableHystrixDashboard
public class Application { public class Application {
protected static ApplicationContext applicationContext; protected static ApplicationContext applicationContext;
@@ -18,7 +20,7 @@ public class Application {
ProductRepository productRepository = applicationContext.getBean(ProductRepository.class); ProductRepository productRepository = applicationContext.getBean(ProductRepository.class);
// 초기 상품 셋팅 // 초기 상품 셋팅
String[] products = {"TV", "RADIO", "NOTEBOOK", "TABLE", "CLOCK"}; String[] products = {"TV", "MASK", "NOTEBOOK", "TABLE", "CLOCK"};
int i = 1; int i = 1;
for(String p : products){ for(String p : products){
Product product = new Product(); Product product = new Product();

View File

@@ -20,10 +20,10 @@ public class ProductController {
private int count = 0; private int count = 0;
private static final String HOSTNAME = parseContainerIdFromHostname( private static final String HOSTNAME = parseContainerIdFromHostname(
System.getenv().getOrDefault("HOSTNAME", "deliveries")); System.getenv().getOrDefault("HOSTNAME", "products"));
static String parseContainerIdFromHostname(String hostname) { static String parseContainerIdFromHostname(String hostname) {
return hostname.replaceAll("deliveries-v\\d+-", ""); return hostname.replaceAll("products-\\d+-", "");
} }
@@ -55,7 +55,7 @@ public class ProductController {
logger.info(String.format("product start from %s: %d", HOSTNAME, count)); logger.info(String.format("product start from %s: %d", HOSTNAME, count));
try { try {
Thread.sleep(500); Thread.sleep(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@@ -10,7 +10,6 @@ spring:
hibernate: hibernate:
show_sql: true show_sql: true
format_sql: true format_sql: true
cloud: cloud:
stream: stream:
kafka: kafka:
@@ -41,7 +40,11 @@ spring:
event-out: event-out:
destination: eventTopic destination: eventTopic
contentType: application/json contentType: application/json
management:
endpoints:
web:
exposure:
include: hystrix.stream, info, health
logging: logging:
level: level:
org.hibernate.type: trace org.hibernate.type: trace

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB