Polish "Add configuration options for Kafka Stream's CleanupConfig"
See gh-23636
This commit is contained in:
@@ -37,7 +37,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.boot.convert.DurationUnit;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.kafka.core.CleanupConfig;
|
||||
import org.springframework.kafka.listener.ContainerProperties.AckMode;
|
||||
import org.springframework.kafka.security.jaas.KafkaJaasLoginModuleInitializer;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -686,6 +685,8 @@ public class KafkaProperties {
|
||||
|
||||
private final Security security = new Security();
|
||||
|
||||
private final Cleanup cleanup = new Cleanup();
|
||||
|
||||
/**
|
||||
* Kafka streams application.id property; default spring.application.name.
|
||||
*/
|
||||
@@ -723,11 +724,6 @@ public class KafkaProperties {
|
||||
*/
|
||||
private String stateDir;
|
||||
|
||||
/**
|
||||
* Cleanup configuration for the state stores.
|
||||
*/
|
||||
private Cleanup cleanup;
|
||||
|
||||
/**
|
||||
* Additional Kafka properties used to configure the streams.
|
||||
*/
|
||||
@@ -741,6 +737,10 @@ public class KafkaProperties {
|
||||
return this.security;
|
||||
}
|
||||
|
||||
public Cleanup getCleanup() {
|
||||
return this.cleanup;
|
||||
}
|
||||
|
||||
public String getApplicationId() {
|
||||
return this.applicationId;
|
||||
}
|
||||
@@ -797,14 +797,6 @@ public class KafkaProperties {
|
||||
this.stateDir = stateDir;
|
||||
}
|
||||
|
||||
public Cleanup getCleanup() {
|
||||
return cleanup;
|
||||
}
|
||||
|
||||
public void setCleanup(Cleanup cleanup) {
|
||||
this.cleanup = cleanup;
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
@@ -1248,6 +1240,36 @@ public class KafkaProperties {
|
||||
|
||||
}
|
||||
|
||||
public static class Cleanup {
|
||||
|
||||
/**
|
||||
* Cleanup the application’s local state directory on startup.
|
||||
*/
|
||||
private boolean onStartup = false;
|
||||
|
||||
/**
|
||||
* Cleanup the application’s local state directory on shutdown.
|
||||
*/
|
||||
private boolean onShutdown = true;
|
||||
|
||||
public boolean isOnStartup() {
|
||||
return this.onStartup;
|
||||
}
|
||||
|
||||
public void setOnStartup(boolean onStartup) {
|
||||
this.onStartup = onStartup;
|
||||
}
|
||||
|
||||
public boolean isOnShutdown() {
|
||||
return this.onShutdown;
|
||||
}
|
||||
|
||||
public void setOnShutdown(boolean onShutdown) {
|
||||
this.onShutdown = onShutdown;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum IsolationLevel {
|
||||
|
||||
/**
|
||||
@@ -1273,32 +1295,6 @@ public class KafkaProperties {
|
||||
|
||||
}
|
||||
|
||||
public static class Cleanup {
|
||||
|
||||
/**
|
||||
* Cleanup the application's state on start.
|
||||
*/
|
||||
private boolean onStart = false;
|
||||
|
||||
/**
|
||||
* Cleanup the application's state on stop.
|
||||
*/
|
||||
private boolean onStop = true;
|
||||
|
||||
public CleanupConfig buildCleanupConfig() {
|
||||
return new CleanupConfig(this.onStart, this.onStop);
|
||||
}
|
||||
|
||||
public boolean isOnStart() {
|
||||
return onStart;
|
||||
}
|
||||
|
||||
public boolean isOnStop() {
|
||||
return onStop;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class Properties extends HashMap<String, Object> {
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.kafka.annotation.KafkaStreamsDefaultConfiguration;
|
||||
import org.springframework.kafka.config.KafkaStreamsConfiguration;
|
||||
import org.springframework.kafka.config.StreamsBuilderFactoryBean;
|
||||
import org.springframework.kafka.core.CleanupConfig;
|
||||
|
||||
/**
|
||||
* Configuration for Kafka Streams annotation-driven support.
|
||||
@@ -91,11 +92,9 @@ class KafkaStreamsAnnotationDrivenConfiguration {
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
this.factoryBean.setAutoStartup(this.properties.getStreams().isAutoStartup());
|
||||
|
||||
KafkaProperties.Cleanup cleanup = this.properties.getStreams().getCleanup();
|
||||
if (cleanup != null) {
|
||||
this.factoryBean.setCleanupConfig(cleanup.buildCleanupConfig());
|
||||
}
|
||||
CleanupConfig cleanupConfig = new CleanupConfig(cleanup.isOnStartup(), cleanup.isOnShutdown());
|
||||
this.factoryBean.setCleanupConfig(cleanupConfig);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user