#35 springboot: custom metric - order ex
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
package hello;
|
||||
|
||||
import hello.order.v0.OrderConfigV0;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.actuate.web.exchanges.InMemoryHttpExchangeRepository;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@SpringBootApplication
|
||||
@Import(OrderConfigV0.class)
|
||||
@SpringBootApplication(scanBasePackages = "hello.controller")
|
||||
public class ActuatorApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package hello.controller;
|
||||
|
||||
import hello.order.OrderService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class OrderController {
|
||||
|
||||
private final OrderService orderService;
|
||||
|
||||
@GetMapping("/order")
|
||||
public String order() {
|
||||
log.info("order");
|
||||
orderService.order();
|
||||
return "order";
|
||||
}
|
||||
|
||||
@GetMapping("/cancel")
|
||||
public String cancel() {
|
||||
log.info("cancel");
|
||||
orderService.cancel();
|
||||
return "cancel";
|
||||
}
|
||||
|
||||
@GetMapping("/stock")
|
||||
public int stock() {
|
||||
log.info("stock");
|
||||
return orderService.getStock().get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package hello.order;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public interface OrderService {
|
||||
void order();
|
||||
void cancel();
|
||||
AtomicInteger getStock();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package hello.order.v0;
|
||||
|
||||
import hello.order.OrderService;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class OrderConfigV0 {
|
||||
|
||||
@Bean
|
||||
OrderService orderService() {
|
||||
return new OrderServiceV0();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package hello.order.v0;
|
||||
|
||||
import hello.order.OrderService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Slf4j
|
||||
public class OrderServiceV0 implements OrderService {
|
||||
|
||||
private final AtomicInteger stock = new AtomicInteger(100);
|
||||
|
||||
@Override
|
||||
public void order() {
|
||||
log.info("주문");
|
||||
stock.decrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
log.info("취소");
|
||||
stock.decrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtomicInteger getStock() {
|
||||
return stock;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user