Skip to content

Commit 53405a4

Browse files
committed
Add property to configure Spring Kafka's authExceptionRetryInterval
Closes gh-44199
1 parent 8c13271 commit 53405a4

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 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.
@@ -237,6 +237,7 @@ private void configureContainer(ContainerProperties container) {
237237
map.from(properties::isMissingTopicsFatal).to(container::setMissingTopicsFatal);
238238
map.from(properties::isImmediateStop).to(container::setStopImmediate);
239239
map.from(properties::isObservationEnabled).to(container::setObservationEnabled);
240+
map.from(properties::getAuthExceptionRetryInterval).to(container::setAuthExceptionRetryInterval);
240241
map.from(this.transactionManager).to(container::setKafkaAwareTransactionManager);
241242
map.from(this.rebalanceListener).to(container::setConsumerRebalanceListener);
242243
map.from(this.listenerTaskExecutor).to(container::setListenerTaskExecutor);

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

+13
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,11 @@ public enum Type {
10801080
*/
10811081
private boolean observationEnabled;
10821082

1083+
/**
1084+
* Time between retries after authentication exceptions.
1085+
*/
1086+
private Duration authExceptionRetryInterval;
1087+
10831088
public Type getType() {
10841089
return this.type;
10851090
}
@@ -1232,6 +1237,14 @@ public void setObservationEnabled(boolean observationEnabled) {
12321237
this.observationEnabled = observationEnabled;
12331238
}
12341239

1240+
public Duration getAuthExceptionRetryInterval() {
1241+
return this.authExceptionRetryInterval;
1242+
}
1243+
1244+
public void setAuthExceptionRetryInterval(Duration authExceptionRetryInterval) {
1245+
this.authExceptionRetryInterval = authExceptionRetryInterval;
1246+
}
1247+
12351248
}
12361249

12371250
public static class Ssl {

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

+10-1
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-2025 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.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.kafka;
1818

19+
import java.time.Duration;
1920
import java.util.function.Function;
2021

2122
import org.junit.jupiter.api.BeforeEach;
@@ -80,4 +81,12 @@ void shouldApplyListenerTaskExecutor() {
8081
assertThat(this.factory.getContainerProperties().getListenerTaskExecutor()).isEqualTo(executor);
8182
}
8283

84+
@Test
85+
void shouldApplyAuthExceptionRetryInterval() {
86+
this.properties.getListener().setAuthExceptionRetryInterval(Duration.ofSeconds(10));
87+
this.configurer.configure(this.factory, this.consumerFactory);
88+
assertThat(this.factory.getContainerProperties().getAuthExceptionRetryInterval())
89+
.isEqualTo(Duration.ofSeconds(10));
90+
}
91+
8392
}

0 commit comments

Comments
 (0)