@@ -92,6 +92,8 @@ public class KafkaAdmin extends KafkaResourceFactory
9292
9393 private boolean initializingContext ;
9494
95+ private boolean modifyTopicConfigs ;
96+
9597 /**
9698 * Create an instance with an {@link AdminClient} based on the supplied
9799 * configuration.
@@ -140,6 +142,16 @@ public void setAutoCreate(boolean autoCreate) {
140142 this .autoCreate = autoCreate ;
141143 }
142144
145+ /**
146+ * Set to true to compare the current topic configuration properties with those in the
147+ * {@link NewTopic} bean, and update if different.
148+ * @param modifyTopicConfigs true to check and update configs if necessary.
149+ * @since 2.8.7
150+ */
151+ public void setModifyTopicConfigs (boolean modifyTopicConfigs ) {
152+ this .modifyTopicConfigs = modifyTopicConfigs ;
153+ }
154+
143155 @ Override
144156 public Map <String , Object > getConfigurationProperties () {
145157 Map <String , Object > configs2 = new HashMap <>(this .configs );
@@ -254,16 +266,19 @@ private void addOrModifyTopicsIfNeeded(AdminClient adminClient, Collection<NewTo
254266 if (topicsWithPartitionMismatches .size () > 0 ) {
255267 createMissingPartitions (adminClient , topicsWithPartitionMismatches );
256268 }
257- Map <ConfigResource , List <ConfigEntry >> mismatchingConfigs =
258- checkTopicsForConfigMismatches (adminClient , topics );
259- if (!mismatchingConfigs .isEmpty ()) {
260- adjustConfigMismatches (adminClient , topics , mismatchingConfigs );
269+ if (this .modifyTopicConfigs ) {
270+ Map <ConfigResource , List <ConfigEntry >> mismatchingConfigs =
271+ checkTopicsForConfigMismatches (adminClient , topics );
272+ if (!mismatchingConfigs .isEmpty ()) {
273+ adjustConfigMismatches (adminClient , topics , mismatchingConfigs );
274+ }
261275 }
262276 }
263277 }
264278
265279 private Map <ConfigResource , List <ConfigEntry >> checkTopicsForConfigMismatches (
266280 AdminClient adminClient , Collection <NewTopic > topics ) {
281+
267282 List <ConfigResource > configResources = topics .stream ()
268283 .map (topic -> new ConfigResource (Type .TOPIC , topic .name ()))
269284 .collect (Collectors .toList ());
@@ -297,10 +312,10 @@ private Map<ConfigResource, List<ConfigEntry>> checkTopicsForConfigMismatches(
297312 }
298313 catch (InterruptedException ie ) {
299314 Thread .currentThread ().interrupt ();
300- throw new KafkaException ("Interrupted while getting topic descriptions" , ie );
315+ throw new KafkaException ("Interrupted while getting topic descriptions:" + topics , ie );
301316 }
302317 catch (ExecutionException | TimeoutException ex ) {
303- throw new KafkaException ("Failed to obtain topic descriptions" , ex );
318+ throw new KafkaException ("Failed to obtain topic descriptions:" + topics , ex );
304319 }
305320 }
306321
0 commit comments