From: Kai Moritz Date: Fri, 10 Jan 2025 16:34:46 +0000 (+0100) Subject: Eindeutigere Methodennamen in `BackOffState` X-Git-Tag: consumer/spring-consumer--error-handling--COMMITS--2025-02~17 X-Git-Url: https://juplo.de/gitweb/?a=commitdiff_plain;h=fd3116a0c32a38d457c04c8db0a0bd01ee033194;p=demos%2Fkafka%2Ftraining Eindeutigere Methodennamen in `BackOffState` --- diff --git a/src/main/java/de/juplo/kafka/BackOffState.java b/src/main/java/de/juplo/kafka/BackOffState.java index b656b10c..e06b8b74 100644 --- a/src/main/java/de/juplo/kafka/BackOffState.java +++ b/src/main/java/de/juplo/kafka/BackOffState.java @@ -71,12 +71,12 @@ class BackOffState } } - boolean isRetryInProgress(long offset) + boolean isStarted(long offset) { return this.offset == offset && timeNextRetryIsDue != null; } - boolean isUnsuccessful() + boolean isCompleted() { return backOffExecution == null && timeNextRetryIsDue != null; } @@ -91,7 +91,7 @@ class BackOffState return Duration.between(startTime, timeNextRetryIsDue); } - void markRetryAsSuccessful() + void markAsCompleted() { if (backOffExecution != null) { diff --git a/src/main/java/de/juplo/kafka/ExampleConsumer.java b/src/main/java/de/juplo/kafka/ExampleConsumer.java index 6cf4bd02..6465a582 100644 --- a/src/main/java/de/juplo/kafka/ExampleConsumer.java +++ b/src/main/java/de/juplo/kafka/ExampleConsumer.java @@ -146,7 +146,7 @@ public class ExampleConsumer implements ConsumerRebalanceListener, Runnable // Seeking to the offset of the record, that raised the exception, and // leaving the loop afterwards, retries the record int partition = topicPartition.partition(); - if (!backOffState[partition].isRetryInProgress(record.offset())) + if (!backOffState[partition].isStarted(record.offset())) { log.info( "{} - First occurrence of a retryable error for offset={} in partition {} - Initializing retry!", @@ -159,7 +159,7 @@ public class ExampleConsumer implements ConsumerRebalanceListener, Runnable } else { - if (backOffState[partition].isUnsuccessful()) + if (backOffState[partition].isCompleted()) { log.warn( "{} - Ignoring retryable error after {} attempts and {}", @@ -185,7 +185,7 @@ public class ExampleConsumer implements ConsumerRebalanceListener, Runnable log.warn("{} - Ignoring non-retryable error!", id, e); } - backOffState[topicPartition.partition()].markRetryAsSuccessful(); + backOffState[topicPartition.partition()].markAsCompleted(); } } }