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>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<!-- Add Stackdriver Trace Starter -->
<!-- <dependency>-->

View File

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

View File

@@ -20,10 +20,10 @@ public class ProductController {
private int count = 0;
private static final String HOSTNAME = parseContainerIdFromHostname(
System.getenv().getOrDefault("HOSTNAME", "deliveries"));
System.getenv().getOrDefault("HOSTNAME", "products"));
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));
try {
Thread.sleep(500);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB