Skip to content

Instantly share code, notes, and snippets.

View kirshiyin89's full-sized avatar

Kirshi Yin kirshiyin89

View GitHub Profile
@kirshiyin89
kirshiyin89 / pom.xml
Created October 25, 2022 12:19
dependencies for kafka retryabletopic
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
@kirshiyin89
kirshiyin89 / KafkaConsumerConfiguration.java
Created October 25, 2022 12:15
Example KafkaConsumerConfiguration for FixedBackOff strategy
@Configuration
public class KafkaConsumerConfiguration {
@Bean
ConcurrentKafkaListenerContainerFactory<String, String> kafkaBlockingRetryContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory);
factory.setCommonErrorHandler(new DefaultErrorHandler(
new DeadLetterPublishingRecoverer(template), new FixedBackOff(5000, 3))
);
@kirshiyin89
kirshiyin89 / services.json
Created October 18, 2022 13:08
Service data response
[
{
"id":"1",
"serviceName":"SERVICE1",
"serviceCase":"TEST1",
"serviceClient":null
},
{
"id":"12",
"serviceName":"SERVICE12",
@kirshiyin89
kirshiyin89 / health.json
Last active October 11, 2022 11:55
Health information with details
{
"status":"UP",
"components":{
"db":{
"status":"UP",
"details":{
"database":"H2",
"validationQuery":"isValid()"
}
},
@kirshiyin89
kirshiyin89 / InventoryChecker.java
Created October 5, 2022 22:04
health checker health checker
@Component
public class InventoryChecker implements HealthIndicator {
private final BookRepository bookRepository;
private static final int MIN_AMOUNT = 10;
public InventoryChecker(BookRepository bookRepository) {
this.bookRepository = bookRepository;
}
public interface BookRepository extends JpaRepository<Book, Long> {
}
@kirshiyin89
kirshiyin89 / Book.java
Created October 5, 2022 22:02
entity book entity
@Entity
@Table(name = "Book")
@Getter
public class Book {
@Id
private Long id;
private String name;
@kirshiyin89
kirshiyin89 / application.yml
Created October 5, 2022 21:56
application.yml
spring:
application:
name: monitoring-demo
datasource:
driverClassName: org.h2.Driver
url: jdbc:h2:mem:testdb
username: sa
password: pass
jpa:
database-platform: org.hibernate.dialect.H2Dialect
@kirshiyin89
kirshiyin89 / pom.xml
Created October 5, 2022 21:54
health dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
package com.univocity.demo.rest;
import com.univocity.demo.dto.CsvData;
import com.univocity.demo.service.CsvDataService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;