Skip to content

Commit 8707399

Browse files
committed
Polish "Group Kafka back-off properties"
See gh-41335
1 parent 14c9893 commit 8707399

File tree

3 files changed

+42
-25
lines changed

3 files changed

+42
-25
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,28 +1548,6 @@ public static class Topic {
15481548
*/
15491549
private int attempts = 3;
15501550

1551-
/**
1552-
* Canonical backoff period. Used as an initial value in the exponential case,
1553-
* and as a minimum value in the uniform case.
1554-
*/
1555-
private Duration delay = Duration.ofSeconds(1);
1556-
1557-
/**
1558-
* Multiplier to use for generating the next backoff delay.
1559-
*/
1560-
private double multiplier = 0.0;
1561-
1562-
/**
1563-
* Maximum wait between retries. If less than the delay then the default of 30
1564-
* seconds is applied.
1565-
*/
1566-
private Duration maxDelay = Duration.ZERO;
1567-
1568-
/**
1569-
* Whether to have the backoff delays.
1570-
*/
1571-
private boolean randomBackOff = false;
1572-
15731551
public boolean isEnabled() {
15741552
return this.enabled;
15751553
}
@@ -1620,8 +1598,7 @@ public void setMaxDelay(Duration maxDelay) {
16201598
getBackoff().setMaxDelay(maxDelay);
16211599
}
16221600

1623-
@DeprecatedConfigurationProperty(replacement = "spring.kafka.retry.topic.backoff.random",
1624-
since = "3.4.0")
1601+
@DeprecatedConfigurationProperty(replacement = "spring.kafka.retry.topic.backoff.random", since = "3.4.0")
16251602
@Deprecated(since = "3.4.0", forRemoval = true)
16261603
public boolean isRandomBackOff() {
16271604
return getBackoff().isRandom();

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,22 @@ void retryTopicConfigurationIsNotEnabledByDefault() {
442442

443443
@Test
444444
void retryTopicConfigurationWithExponentialBackOff() {
445+
this.contextRunner.withPropertyValues("spring.application.name=my-test-app",
446+
"spring.kafka.bootstrap-servers=localhost:9092,localhost:9093", "spring.kafka.retry.topic.enabled=true",
447+
"spring.kafka.retry.topic.attempts=5", "spring.kafka.retry.topic.backoff.delay=100ms",
448+
"spring.kafka.retry.topic.backoff.multiplier=2", "spring.kafka.retry.topic.backoff.max-delay=300ms")
449+
.run((context) -> {
450+
RetryTopicConfiguration configuration = context.getBean(RetryTopicConfiguration.class);
451+
assertThat(configuration.getDestinationTopicProperties()).hasSize(5)
452+
.extracting(DestinationTopic.Properties::delay, DestinationTopic.Properties::suffix)
453+
.containsExactly(tuple(0L, ""), tuple(100L, "-retry-0"), tuple(200L, "-retry-1"),
454+
tuple(300L, "-retry-2"), tuple(0L, "-dlt"));
455+
});
456+
}
457+
458+
@Test
459+
@Deprecated(since = "3.4.0", forRemoval = true)
460+
void retryTopicConfigurationWithExponentialBackOffUsingDeprecatedProperties() {
445461
this.contextRunner.withPropertyValues("spring.application.name=my-test-app",
446462
"spring.kafka.bootstrap-servers=localhost:9092,localhost:9093", "spring.kafka.retry.topic.enabled=true",
447463
"spring.kafka.retry.topic.attempts=5", "spring.kafka.retry.topic.delay=100ms",
@@ -471,6 +487,18 @@ void retryTopicConfigurationWithDefaultProperties() {
471487

472488
@Test
473489
void retryTopicConfigurationWithFixedBackOff() {
490+
this.contextRunner.withPropertyValues("spring.application.name=my-test-app",
491+
"spring.kafka.bootstrap-servers=localhost:9092,localhost:9093", "spring.kafka.retry.topic.enabled=true",
492+
"spring.kafka.retry.topic.attempts=4", "spring.kafka.retry.topic.backoff.delay=2s")
493+
.run(assertRetryTopicConfiguration(
494+
(configuration) -> assertThat(configuration.getDestinationTopicProperties()).hasSize(3)
495+
.extracting(DestinationTopic.Properties::delay)
496+
.containsExactly(0L, 2000L, 0L)));
497+
}
498+
499+
@Test
500+
@Deprecated(since = "3.4.0", forRemoval = true)
501+
void retryTopicConfigurationWithFixedBackOffUsingDeprecatedProperties() {
474502
this.contextRunner.withPropertyValues("spring.application.name=my-test-app",
475503
"spring.kafka.bootstrap-servers=localhost:9092,localhost:9093", "spring.kafka.retry.topic.enabled=true",
476504
"spring.kafka.retry.topic.attempts=4", "spring.kafka.retry.topic.delay=2s")
@@ -482,6 +510,18 @@ void retryTopicConfigurationWithFixedBackOff() {
482510

483511
@Test
484512
void retryTopicConfigurationWithNoBackOff() {
513+
this.contextRunner.withPropertyValues("spring.application.name=my-test-app",
514+
"spring.kafka.bootstrap-servers=localhost:9092,localhost:9093", "spring.kafka.retry.topic.enabled=true",
515+
"spring.kafka.retry.topic.attempts=4", "spring.kafka.retry.topic.backoff.delay=0")
516+
.run(assertRetryTopicConfiguration(
517+
(configuration) -> assertThat(configuration.getDestinationTopicProperties()).hasSize(3)
518+
.extracting(DestinationTopic.Properties::delay)
519+
.containsExactly(0L, 0L, 0L)));
520+
}
521+
522+
@Test
523+
@Deprecated(since = "3.4.0", forRemoval = true)
524+
void retryTopicConfigurationWithNoBackOffUsingDeprecatedProperties() {
485525
this.contextRunner.withPropertyValues("spring.application.name=my-test-app",
486526
"spring.kafka.bootstrap-servers=localhost:9092,localhost:9093", "spring.kafka.retry.topic.enabled=true",
487527
"spring.kafka.retry.topic.attempts=4", "spring.kafka.retry.topic.delay=0")

0 commit comments

Comments
 (0)