@@ -140,6 +140,8 @@ public class KafkaMessageListenerContainer<K, V> // NOSONAR line count
140
140
141
141
private static final int DEFAULT_ACK_TIME = 5000 ;
142
142
143
+ private static final Map <String , Object > CONSUMER_CONFIG_DEFAULTS = ConsumerConfig .configDef ().defaultValues ();
144
+
143
145
private final AbstractMessageListenerContainer <K , V > thisOrParentContainer ;
144
146
145
147
private final TopicPartitionOffset [] topicPartitions ;
@@ -433,8 +435,6 @@ private final class ListenerConsumer implements SchedulingAwareRunnable, Consume
433
435
434
436
private static final String ERROR_HANDLER_THREW_AN_EXCEPTION = "Error handler threw an exception" ;
435
437
436
- private static final int SIXTY = 60 ;
437
-
438
438
private static final String UNCHECKED = "unchecked" ;
439
439
440
440
private static final String RAWTYPES = "rawtypes" ;
@@ -592,7 +592,7 @@ private final class ListenerConsumer implements SchedulingAwareRunnable, Consume
592
592
593
593
@ SuppressWarnings (UNCHECKED )
594
594
ListenerConsumer (GenericMessageListener <?> listener , ListenerType listenerType ) {
595
- Properties consumerProperties = new Properties ( this . containerProperties . getKafkaConsumerProperties () );
595
+ Properties consumerProperties = propertiesFromProperties ( );
596
596
checkGroupInstance (consumerProperties , KafkaMessageListenerContainer .this .consumerFactory );
597
597
this .autoCommit = determineAutoCommit (consumerProperties );
598
598
this .consumer =
@@ -676,6 +676,20 @@ else if (listener instanceof MessageListener) {
676
676
this .subBatchPerPartition = setupSubBatchPerPartition ();
677
677
}
678
678
679
+ private Properties propertiesFromProperties () {
680
+ Properties propertyOverrides = this .containerProperties .getKafkaConsumerProperties ();
681
+ Properties props = new Properties ();
682
+ props .putAll (propertyOverrides );
683
+ Set <String > stringPropertyNames = propertyOverrides .stringPropertyNames ();
684
+ // User might have provided properties as defaults
685
+ stringPropertyNames .forEach ((name ) -> {
686
+ if (!props .contains (name )) {
687
+ props .setProperty (name , propertyOverrides .getProperty (name ));
688
+ }
689
+ });
690
+ return props ;
691
+ }
692
+
679
693
String getClientId () {
680
694
return this .clientId ;
681
695
}
@@ -770,9 +784,9 @@ else if (timeout instanceof String) {
770
784
this .logger .warn (() -> "Unexpected type: " + timeoutToLog .getClass ().getName ()
771
785
+ " in property '"
772
786
+ ConsumerConfig .MAX_POLL_INTERVAL_MS_CONFIG
773
- + "'; defaulting to 30 seconds ." );
787
+ + "'; using Kafka default ." );
774
788
}
775
- return Duration . ofSeconds ( SIXTY / 2 ). toMillis (); // Default 'max.poll.interval.ms' is 30 seconds
789
+ return ( int ) CONSUMER_CONFIG_DEFAULTS . get ( ConsumerConfig . MAX_POLL_INTERVAL_MS_CONFIG );
776
790
}
777
791
}
778
792
@@ -855,12 +869,12 @@ else if (timeout instanceof String) {
855
869
this .logger .warn (() -> "Unexpected type: " + timeoutToLog .getClass ().getName ()
856
870
+ " in property '"
857
871
+ ConsumerConfig .DEFAULT_API_TIMEOUT_MS_CONFIG
858
- + "'; defaulting to 60 seconds for sync commit timeouts" );
872
+ + "'; defaulting to Kafka default for sync commit timeouts" );
859
873
}
860
- return Duration .ofSeconds (SIXTY );
874
+ return Duration
875
+ .ofMillis ((int ) CONSUMER_CONFIG_DEFAULTS .get (ConsumerConfig .DEFAULT_API_TIMEOUT_MS_CONFIG ));
861
876
}
862
877
}
863
-
864
878
}
865
879
866
880
private Object findDeserializerClass (Map <String , Object > props , boolean isValue ) {
0 commit comments