req-res 방식 추가에 따른 변경사항 적용
This commit is contained in:
11
pom.xml
11
pom.xml
@@ -79,17 +79,6 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- hystrix circuit breaker -->
|
||||
<dependency>
|
||||
<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>-->
|
||||
<!-- <groupId>org.springframework.cloud</groupId>-->
|
||||
|
||||
@@ -3,15 +3,11 @@ package com.example.template;
|
||||
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;
|
||||
|
||||
@@ -1,41 +1,26 @@
|
||||
package com.example.template;
|
||||
|
||||
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
public class ProductController {
|
||||
|
||||
|
||||
private static final String RESPONSE_STRING_FORMAT = "product change from '%s': %d";
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
ProductService productService;
|
||||
|
||||
private int count = 0;
|
||||
|
||||
private static final String HOSTNAME = parseContainerIdFromHostname(
|
||||
System.getenv().getOrDefault("HOSTNAME", "products"));
|
||||
|
||||
static String parseContainerIdFromHostname(String hostname) {
|
||||
return hostname.replaceAll("products-\\d+-", "");
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/product/{productId}")
|
||||
Product productStockCheck(@PathVariable(value = "productId") Long productId) {
|
||||
|
||||
System.out.println("productStockCheck call");
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// System.out.println("productStockCheck call");
|
||||
// try {
|
||||
// Thread.sleep(500);
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
return this.productService.getProductById(productId);
|
||||
}
|
||||
@@ -46,28 +31,4 @@ public class ProductController {
|
||||
return this.productService.save(data);
|
||||
}
|
||||
|
||||
|
||||
@PatchMapping("/product/{productId}")
|
||||
@HystrixCommand(fallbackMethod = "certifyFallBack")
|
||||
ResponseEntity<String> fakeProductPatch(@PathVariable(value = "productId") Long productId, @RequestBody String data) {
|
||||
|
||||
count++;
|
||||
logger.info(String.format("product start from %s: %d", HOSTNAME, count));
|
||||
|
||||
// try {
|
||||
// Thread.sleep(900);
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
return ResponseEntity.ok(String.format(RESPONSE_STRING_FORMAT, HOSTNAME, count));
|
||||
}
|
||||
|
||||
ResponseEntity<String> certifyFallBack(Long productId, String data){
|
||||
|
||||
System.out.println("certifyFallBack");
|
||||
System.out.println(data);
|
||||
|
||||
return ResponseEntity.ok("시스템이 혼잡합니다!! 잠시후 다시 호출해주세요");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user