#35 springboot: custom metric - counter with aop
This commit is contained in:
@@ -2,6 +2,7 @@ package hello;
|
||||
|
||||
import hello.order.v0.OrderConfigV0;
|
||||
import hello.order.v1.OrderConfigV1;
|
||||
import hello.order.v2.OrderConfigV2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.actuate.web.exchanges.InMemoryHttpExchangeRepository;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -9,7 +10,8 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
//@Import(OrderConfigV0.class)
|
||||
@Import(OrderConfigV1.class)
|
||||
//@Import(OrderConfigV1.class)
|
||||
@Import(OrderConfigV2.class)
|
||||
@SpringBootApplication(scanBasePackages = "hello.controller")
|
||||
public class ActuatorApplication {
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package hello.order.v2;
|
||||
|
||||
import hello.order.OrderService;
|
||||
import io.micrometer.core.aop.CountedAspect;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class OrderConfigV2 {
|
||||
|
||||
@Bean
|
||||
public OrderService orderService() {
|
||||
return new OrderServiceV2();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CountedAspect countedAspect(MeterRegistry registry) {
|
||||
return new CountedAspect(registry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package hello.order.v2;
|
||||
|
||||
import hello.order.OrderService;
|
||||
import io.micrometer.core.annotation.Counted;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Slf4j
|
||||
public class OrderServiceV2 implements OrderService {
|
||||
|
||||
private final AtomicInteger stock = new AtomicInteger(100);
|
||||
|
||||
@Counted("my.order")
|
||||
@Override
|
||||
public void order() {
|
||||
log.info("주문");
|
||||
stock.decrementAndGet();
|
||||
}
|
||||
|
||||
@Counted("my.order")
|
||||
@Override
|
||||
public void cancel() {
|
||||
log.info("취소");
|
||||
stock.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtomicInteger getStock() {
|
||||
return stock;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user