This file contains 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
public static int generateNumberFromRange(int maxRange) throws NoSuchAlgorithmException { | |
Random rand = SecureRandom.getInstanceStrong(); | |
int randomNum; | |
if (maxRange == 100) { | |
randomNum = rand.nextInt(maxRange / 2) * 2; | |
} else { | |
randomNum = rand.nextInt(maxRange / 2) * 2 + 1; | |
} | |
return randomNum; | |
} |
This file contains 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
@SpringBootApplication | |
public class KafkaErrorHandlingApplication { | |
public static void main(String[] args) { | |
SpringApplication.run(KafkaErrorHandlingApplication.class, args); | |
} | |
} |
This file contains 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 | |
@Slf4j | |
public class ProducerController { | |
private final KafkaTemplate<String, String> kafkaTemplate; | |
@Value("${topic}") | |
private String topic; |
This file contains 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 | |
@Slf4j | |
public class MyKafkaListener { | |
@RetryableTopic( | |
attempts = "5", | |
topicSuffixingStrategy = TopicSuffixingStrategy.SUFFIX_WITH_INDEX_VALUE, | |
backoff = @Backoff(delay = 1000, multiplier = 2.0), | |
exclude = {SerializationException.class, DeserializationException.class} |
This file contains 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
topic: my-topic | |
server: | |
port: 8090 | |
spring: | |
kafka: | |
bootstrap-servers: http://localhost:29092 | |
properties: | |
spring.deserializer.value.delegate.class: org.springframework.kafka.support.serializer.JsonDeserializer | |
security.protocol: PLAINTEXT |
This file contains 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
version: '2.1' | |
networks: | |
app-tier: | |
driver: bridge | |
services: | |
zookeeper: | |
image: confluentinc/cp-zookeeper:latest | |
environment: | |
ZOOKEEPER_CLIENT_PORT: 2181 |
This file contains 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
<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> |
This file contains 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
@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)) | |
); |
This file contains 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
[ | |
{ | |
"id":"1", | |
"serviceName":"SERVICE1", | |
"serviceCase":"TEST1", | |
"serviceClient":null | |
}, | |
{ | |
"id":"12", | |
"serviceName":"SERVICE12", |
This file contains 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
{ | |
"status":"UP", | |
"components":{ | |
"db":{ | |
"status":"UP", | |
"details":{ | |
"database":"H2", | |
"validationQuery":"isValid()" | |
} | |
}, |
NewerOlder