This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.github.sonus21.rqueue.annotation.RqueueListener; | |
| import lombok.extern.slf4j.Slf4j; | |
| import org.springframework.stereotype.Component; | |
| @Component | |
| @Slf4j | |
| public class MessageListener { | |
| @RqueueListener(value = "${email.queue.name}") | |
| public void sendEmail(Email email) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import lombok.AllArgsConstructor; | |
| import lombok.Data; | |
| import lombok.NoArgsConstructor; | |
| @Data | |
| @AllArgsConstructor | |
| @NoArgsConstructor | |
| public class Email { | |
| private String email; | |
| private String subject; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import lombok.AllArgsConstructor; | |
| import lombok.Data; | |
| import lombok.NoArgsConstructor; | |
| @Data | |
| @AllArgsConstructor | |
| @NoArgsConstructor | |
| public class Invoice { | |
| private String id; | |
| private String type; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RestController | |
| @RequiredArgsConstructor(onConstructor = @__(@Autowired)) | |
| @Slf4j | |
| public class Controller { | |
| private @NonNull RqueueMessageEnqueuer rqueueMessageEnqueuer; | |
| @Value("${email.queue.name}") | |
| private String emailQueueName; | |
| @Value("${invoice.queue.name}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| email.queue.name=email-queue | |
| invoice.queue.name=invoice-queue | |
| # 30 seconds delay for invoice | |
| invoice.queue.delay=300000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dependencies { | |
| implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | |
| implementation 'org.springframework.boot:spring-boot-starter-web' | |
| compileOnly 'org.projectlombok:lombok' | |
| annotationProcessor 'org.projectlombok:lombok' | |
| providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' | |
| implementation 'io.micrometer:micrometer-registry-prometheus' | |
| implementation 'org.springframework.boot:spring-boot-starter-actuator' | |
| // https://mvnrepository.com/artifact/com.h2database/h2 | |
| compile group: 'com.h2database', name: 'h2', version: '1.4.200' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Enable prometheus exporter | |
| management.metrics.export.prometheus.enabled=true | |
| # Enable prometheus end point | |
| management.endpoints.web.exposure.include=prometheus | |
| # enable percentile-based histogram for http requests | |
| management.metrics.distribution.percentiles-histogram.http.server.requests=true | |
| # http SLA histogram buckets | |
| management.metrics.distribution.sla.http.server.requests=100ms,150ms,250ms,500ms,1s | |
| # enable JVM metrics | |
| management.metrics.enable.jvm=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| public class StockManager { | |
| @Autowired private MeterRegistry meterRegistry; | |
| private List<String> orders = new Vector<>(); | |
| private Counter counter; | |
| private Gauge gauge; | |
| @PostConstruct | |
| public void init() { | |
| counter = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RestController | |
| @RequestMapping(path = "stocks") | |
| @RequiredArgsConstructor(onConstructor = @__(@Autowired)) | |
| public class StockController { | |
| @NonNull private StockManager stockManager; | |
| @GetMapping | |
| @ResponseBody | |
| public List<String> getItems(@RequestParam int size) { | |
| return stockManager.getItem(size); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Aspect | |
| @Component | |
| public class ControllerProfiler { | |
| private static Map<String, Object> timedAnnotationData = new HashMap<>(); | |
| static { | |
| // use percentile data of p90, p95, p99.99 | |
| double[] percentiles = {0.90, 0.95, 0.9999}; | |
| // set histogram to true | |
| timedAnnotationData.put("histogram", true); |