17
17
package org .springframework .kafka .core ;
18
18
19
19
import java .util .Map ;
20
+ import java .util .Properties ;
20
21
import java .util .concurrent .TimeUnit ;
21
22
22
23
import org .apache .kafka .streams .KafkaClientSupplier ;
@@ -56,6 +57,8 @@ public class StreamsBuilderFactoryBean extends AbstractFactoryBean<StreamsBuilde
56
57
57
58
private StreamsConfig streamsConfig ;
58
59
60
+ private Properties properties ;
61
+
59
62
private final CleanupConfig cleanupConfig ;
60
63
61
64
private KafkaStreamsCustomizer kafkaStreamsCustomizer ;
@@ -77,9 +80,10 @@ public class StreamsBuilderFactoryBean extends AbstractFactoryBean<StreamsBuilde
77
80
private volatile boolean running ;
78
81
79
82
/**
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)}.
83
87
* @since 2.1.3.
84
88
*/
85
89
public StreamsBuilderFactoryBean () {
@@ -100,29 +104,58 @@ public StreamsBuilderFactoryBean(StreamsConfig streamsConfig) {
100
104
* @param streamsConfig the streams configuration.
101
105
* @param cleanupConfig the cleanup configuration.
102
106
* @since 2.1.2.
107
+ * @deprecated in favor of {@link #StreamsBuilderFactoryBean(Properties, CleanupConfig)}
103
108
*/
109
+ @ Deprecated
104
110
public StreamsBuilderFactoryBean (StreamsConfig streamsConfig , CleanupConfig cleanupConfig ) {
105
111
Assert .notNull (streamsConfig , "'streamsConfig' must not be null" );
106
112
Assert .notNull (cleanupConfig , "'cleanupConfig' must not be null" );
107
113
this .streamsConfig = streamsConfig ;
108
114
this .cleanupConfig = cleanupConfig ;
109
115
}
110
116
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
+
111
131
/**
112
132
* Construct an instance with the supplied streams configuration.
113
133
* @param streamsConfig the streams configuration.
134
+ * @deprecated in favor of {@link #StreamsBuilderFactoryBean(Properties)}.
114
135
*/
136
+ @ Deprecated
115
137
public StreamsBuilderFactoryBean (Map <String , Object > streamsConfig ) {
116
138
this (streamsConfig , new CleanupConfig ());
117
139
}
118
140
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
+
119
150
/**
120
151
* Construct an instance with the supplied streams configuration and
121
152
* clean up configuration.
122
153
* @param streamsConfig the streams configuration.
123
154
* @param cleanupConfig the cleanup configuration.
124
155
* @since 2.1.2.
156
+ * @deprecated in favor of {@link #StreamsBuilderFactoryBean(Properties, CleanupConfig)}.
125
157
*/
158
+ @ Deprecated
126
159
public StreamsBuilderFactoryBean (Map <String , Object > streamsConfig , CleanupConfig cleanupConfig ) {
127
160
Assert .notNull (streamsConfig , "'streamsConfig' must not be null" );
128
161
Assert .notNull (cleanupConfig , "'cleanupConfig' must not be null" );
@@ -137,6 +170,7 @@ public StreamsBuilderFactoryBean(Map<String, Object> streamsConfig, CleanupConfi
137
170
*/
138
171
public void setStreamsConfig (StreamsConfig streamsConfig ) {
139
172
Assert .notNull (streamsConfig , "'streamsConfig' must not be null" );
173
+ Assert .isNull (this .properties , "Cannot have both streamsConfig and streams configuration properties" );
140
174
this .streamsConfig = streamsConfig ;
141
175
}
142
176
@@ -145,6 +179,22 @@ public StreamsConfig getStreamsConfig() {
145
179
return this .streamsConfig ;
146
180
}
147
181
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
+
148
198
public void setClientSupplier (KafkaClientSupplier clientSupplier ) {
149
199
Assert .notNull (clientSupplier , "'clientSupplier' must not be null" );
150
200
this .clientSupplier = clientSupplier ; // NOSONAR (sync)
@@ -191,7 +241,8 @@ public Class<?> getObjectType() {
191
241
@ Override
192
242
protected StreamsBuilder createInstance () throws Exception {
193
243
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" );
195
246
}
196
247
return new StreamsBuilder ();
197
248
}
@@ -217,16 +268,23 @@ public void stop(Runnable callback) {
217
268
}
218
269
}
219
270
271
+ @ SuppressWarnings ("deprecation" )
220
272
@ Override
221
273
public synchronized void start () {
222
274
if (!this .running ) {
223
275
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" );
225
278
Topology topology = getObject ().build ();
226
279
if (logger .isDebugEnabled ()) {
227
280
logger .debug (topology .describe ());
228
281
}
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
+ }
230
288
this .kafkaStreams .setStateListener (this .stateListener );
231
289
this .kafkaStreams .setGlobalStateRestoreListener (this .stateRestoreListener );
232
290
this .kafkaStreams .setUncaughtExceptionHandler (this .uncaughtExceptionHandler );
0 commit comments