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
@JvmInline | |
value class PaymentMethod(val paymentMethod: String) | |
@JvmInline | |
value class PaymentId(val paymentId: UUID) | |
data class Payment( | |
val paymentId: PaymentId, | |
val paymentMethod: PaymentMethod | |
) |
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
val Any.log: Logger get() = LoggerFactory.getLogger(this::class.java) |
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
object ErrorHandler { | |
fun handleError(error: Error) = when(error) { | |
is ValidationError -> log.error("a validation error has occured") | |
is IOError -> log.error("an IO error has occured") | |
is FatalError -> log.error("a Fatal error has occured... exiting") | |
} | |
} |
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
sealed class Error { | |
data class ValidationError(val id: Long, val message: String): Error() | |
data class IOError(val message: String, val throwable: Throwable): Error() | |
object FatalError : Error() | |
} |
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
import org.apache.kafka.common.errors.SerializationException | |
import org.slf4j.LoggerFactory | |
import org.springframework.context.annotation.Profile | |
import org.springframework.kafka.annotation.KafkaListener | |
import org.springframework.kafka.annotation.RetryableTopic | |
import org.springframework.kafka.retrytopic.DltStrategy | |
import org.springframework.kafka.retrytopic.TopicSuffixingStrategy | |
import org.springframework.kafka.support.converter.ConversionException | |
import org.springframework.kafka.support.serializer.DeserializationException | |
import org.springframework.messaging.converter.MessageConversionException |
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
import org.springframework.boot.autoconfigure.kafka.KafkaProperties | |
import org.springframework.context.annotation.Bean | |
import org.springframework.context.annotation.Configuration | |
import org.springframework.context.annotation.Profile | |
import org.springframework.kafka.annotation.EnableKafka | |
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory | |
import org.springframework.kafka.core.ConsumerFactory | |
import org.springframework.kafka.core.DefaultKafkaConsumerFactory | |
import org.springframework.kafka.core.DefaultKafkaProducerFactory | |
import org.springframework.kafka.core.KafkaTemplate |
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 | |
retry-attempts: 8 | |
server: | |
port: 8080 | |
management: | |
server.port: 8081 | |
spring: | |
kafka: | |
bootstrap-servers: http://localhost:29092 | |
properties: |
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
@Bean | |
fun errorHandler(kafkaProperties: KafkaProperties): DefaultErrorHandler = | |
run { | |
val backOff = ExponentialBackOff(3000, 2.0) | |
backOff.maxElapsedTime = 60000 | |
DefaultErrorHandler(DeadLetterPublishingRecoverer(errorKafkaTemplate(kafkaProperties)), backOff) | |
} |
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 | |
class FixedBackOffKafkaListener { | |
private val log = LoggerFactory.getLogger(FixedBackOffKafkaListener::class.java) | |
@KafkaListener( | |
id = "\${spring.kafka.consumer.group-id}", | |
topics = ["\${topic}"] | |
) | |
fun onReceive(message: String) { | |
log.info("processing message: $message") |
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
import org.springframework.boot.autoconfigure.kafka.KafkaProperties | |
import org.springframework.context.annotation.Bean | |
import org.springframework.context.annotation.Configuration | |
import org.springframework.context.annotation.Profile | |
import org.springframework.kafka.annotation.EnableKafka | |
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory | |
import org.springframework.kafka.core.ConsumerFactory | |
import org.springframework.kafka.core.DefaultKafkaConsumerFactory | |
import org.springframework.kafka.core.DefaultKafkaProducerFactory | |
import org.springframework.kafka.core.KafkaTemplate |
NewerOlder