1717package org .springframework .kafka .core ;
1818
1919import java .util .Map ;
20+ import java .util .Properties ;
2021import java .util .concurrent .TimeUnit ;
2122
2223import org .apache .kafka .streams .KafkaClientSupplier ;
@@ -56,6 +57,8 @@ public class StreamsBuilderFactoryBean extends AbstractFactoryBean<StreamsBuilde
5657
5758 private StreamsConfig streamsConfig ;
5859
60+ private Properties properties ;
61+
5962 private final CleanupConfig cleanupConfig ;
6063
6164 private KafkaStreamsCustomizer kafkaStreamsCustomizer ;
@@ -77,9 +80,10 @@ public class StreamsBuilderFactoryBean extends AbstractFactoryBean<StreamsBuilde
7780 private volatile boolean running ;
7881
7982 /**
80- * Default constructor that creates the factory without a {@link StreamsConfig}.
81- * It is the factory user's responsibility to properly set {@link StreamsConfig}
82- * using {@link StreamsBuilderFactoryBean#setStreamsConfig(StreamsConfig)}
83+ * Default constructor that creates the factory without configuration
84+ * {@link Properties}. It is the factory user's responsibility to properly set
85+ * {@link Properties} using
86+ * {@link StreamsBuilderFactoryBean#setStreamsConfiguration(Properties)}.
8387 * @since 2.1.3.
8488 */
8589 public StreamsBuilderFactoryBean () {
@@ -100,29 +104,58 @@ public StreamsBuilderFactoryBean(StreamsConfig streamsConfig) {
100104 * @param streamsConfig the streams configuration.
101105 * @param cleanupConfig the cleanup configuration.
102106 * @since 2.1.2.
107+ * @deprecated in favor of {@link #StreamsBuilderFactoryBean(Properties, CleanupConfig)}
103108 */
109+ @ Deprecated
104110 public StreamsBuilderFactoryBean (StreamsConfig streamsConfig , CleanupConfig cleanupConfig ) {
105111 Assert .notNull (streamsConfig , "'streamsConfig' must not be null" );
106112 Assert .notNull (cleanupConfig , "'cleanupConfig' must not be null" );
107113 this .streamsConfig = streamsConfig ;
108114 this .cleanupConfig = cleanupConfig ;
109115 }
110116
117+ /**
118+ * Construct an instance with the supplied streams configuration and
119+ * clean up configuration.
120+ * @param streamsConfig the streams configuration.
121+ * @param cleanupConfig the cleanup configuration.
122+ * @since 2.2
123+ */
124+ public StreamsBuilderFactoryBean (Properties streamsConfig , CleanupConfig cleanupConfig ) {
125+ Assert .notNull (streamsConfig , "'streamsConfig' must not be null" );
126+ Assert .notNull (cleanupConfig , "'cleanupConfig' must not be null" );
127+ this .properties = streamsConfig ;
128+ this .cleanupConfig = cleanupConfig ;
129+ }
130+
111131 /**
112132 * Construct an instance with the supplied streams configuration.
113133 * @param streamsConfig the streams configuration.
134+ * @deprecated in favor of {@link #StreamsBuilderFactoryBean(Properties)}.
114135 */
136+ @ Deprecated
115137 public StreamsBuilderFactoryBean (Map <String , Object > streamsConfig ) {
116138 this (streamsConfig , new CleanupConfig ());
117139 }
118140
141+ /**
142+ * Construct an instance with the supplied streams configuration.
143+ * @param streamsConfig the streams configuration.
144+ * @since 2.2
145+ */
146+ public StreamsBuilderFactoryBean (Properties streamsConfig ) {
147+ this (streamsConfig , new CleanupConfig ());
148+ }
149+
119150 /**
120151 * Construct an instance with the supplied streams configuration and
121152 * clean up configuration.
122153 * @param streamsConfig the streams configuration.
123154 * @param cleanupConfig the cleanup configuration.
124155 * @since 2.1.2.
156+ * @deprecated in favor of {@link #StreamsBuilderFactoryBean(Properties, CleanupConfig)}.
125157 */
158+ @ Deprecated
126159 public StreamsBuilderFactoryBean (Map <String , Object > streamsConfig , CleanupConfig cleanupConfig ) {
127160 Assert .notNull (streamsConfig , "'streamsConfig' must not be null" );
128161 Assert .notNull (cleanupConfig , "'cleanupConfig' must not be null" );
@@ -137,6 +170,7 @@ public StreamsBuilderFactoryBean(Map<String, Object> streamsConfig, CleanupConfi
137170 */
138171 public void setStreamsConfig (StreamsConfig streamsConfig ) {
139172 Assert .notNull (streamsConfig , "'streamsConfig' must not be null" );
173+ Assert .isNull (this .properties , "Cannot have both streamsConfig and streams configuration properties" );
140174 this .streamsConfig = streamsConfig ;
141175 }
142176
@@ -145,6 +179,22 @@ public StreamsConfig getStreamsConfig() {
145179 return this .streamsConfig ;
146180 }
147181
182+ /**
183+ * Set {@link StreamsConfig} on this factory.
184+ * @param streamsConfig the streams configuration.
185+ * @since 2.2
186+ */
187+ public void setStreamsConfiguration (Properties streamsConfig ) {
188+ Assert .notNull (streamsConfig , "'streamsConfig' must not be null" );
189+ Assert .isNull (this .streamsConfig , "Cannot have both streamsConfig and streams configuration properties" );
190+ this .properties = streamsConfig ;
191+ }
192+
193+ @ Nullable
194+ public Properties getStreamsConfiguration () {
195+ return this .properties ;
196+ }
197+
148198 public void setClientSupplier (KafkaClientSupplier clientSupplier ) {
149199 Assert .notNull (clientSupplier , "'clientSupplier' must not be null" );
150200 this .clientSupplier = clientSupplier ; // NOSONAR (sync)
@@ -191,7 +241,8 @@ public Class<?> getObjectType() {
191241 @ Override
192242 protected StreamsBuilder createInstance () throws Exception {
193243 if (this .autoStartup ) {
194- Assert .notNull (this .streamsConfig , "'streamsConfig' must not be null" );
244+ Assert .state (this .streamsConfig != null || this .properties != null ,
245+ "'streamsConfig' or streams configuration properties must not be null" );
195246 }
196247 return new StreamsBuilder ();
197248 }
@@ -217,16 +268,23 @@ public void stop(Runnable callback) {
217268 }
218269 }
219270
271+ @ SuppressWarnings ("deprecation" )
220272 @ Override
221273 public synchronized void start () {
222274 if (!this .running ) {
223275 try {
224- Assert .notNull (this .streamsConfig , "'streamsConfig' must not be null" );
276+ Assert .state (this .streamsConfig != null || this .properties != null ,
277+ "'streamsConfig' or streams configuration properties must not be null" );
225278 Topology topology = getObject ().build ();
226279 if (logger .isDebugEnabled ()) {
227280 logger .debug (topology .describe ());
228281 }
229- this .kafkaStreams = new KafkaStreams (topology , this .streamsConfig , this .clientSupplier );
282+ if (this .properties != null ) {
283+ this .kafkaStreams = new KafkaStreams (topology , this .properties , this .clientSupplier );
284+ }
285+ else {
286+ this .kafkaStreams = new KafkaStreams (topology , this .streamsConfig , this .clientSupplier );
287+ }
230288 this .kafkaStreams .setStateListener (this .stateListener );
231289 this .kafkaStreams .setGlobalStateRestoreListener (this .stateRestoreListener );
232290 this .kafkaStreams .setUncaughtExceptionHandler (this .uncaughtExceptionHandler );
0 commit comments