@@ -141,6 +141,8 @@ public class KafkaMessageListenerContainer<K, V> // NOSONAR line count
141141 private static final boolean MICROMETER_PRESENT = ClassUtils .isPresent (
142142 "io.micrometer.core.instrument.MeterRegistry" , KafkaMessageListenerContainer .class .getClassLoader ());
143143
144+ private static final Map <String , Object > CONSUMER_CONFIG_DEFAULTS = ConsumerConfig .configDef ().defaultValues ();
145+
144146 private final AbstractMessageListenerContainer <K , V > thisOrParentContainer ;
145147
146148 private final TopicPartitionOffset [] topicPartitions ;
@@ -468,8 +470,6 @@ public String toString() {
468470
469471 private final class ListenerConsumer implements SchedulingAwareRunnable , ConsumerSeekCallback {
470472
471- private static final int SIXTY = 60 ;
472-
473473 private static final String UNCHECKED = "unchecked" ;
474474
475475 private static final String RAWTYPES = "rawtypes" ;
@@ -615,7 +615,7 @@ private final class ListenerConsumer implements SchedulingAwareRunnable, Consume
615615
616616 @ SuppressWarnings (UNCHECKED )
617617 ListenerConsumer (GenericMessageListener <?> listener , ListenerType listenerType ) {
618- Properties consumerProperties = new Properties ( this . containerProperties . getKafkaConsumerProperties () );
618+ Properties consumerProperties = propertiesFromProperties ( );
619619 checkGroupInstance (consumerProperties , KafkaMessageListenerContainer .this .consumerFactory );
620620 this .autoCommit = determineAutoCommit (consumerProperties );
621621 this .consumer =
@@ -696,6 +696,20 @@ else if (listener instanceof MessageListener) {
696696 this .micrometerHolder = obtainMicrometerHolder ();
697697 }
698698
699+ private Properties propertiesFromProperties () {
700+ Properties propertyOverrides = this .containerProperties .getKafkaConsumerProperties ();
701+ Properties props = new Properties ();
702+ props .putAll (propertyOverrides );
703+ Set <String > stringPropertyNames = propertyOverrides .stringPropertyNames ();
704+ // User might have provided properties as defaults
705+ stringPropertyNames .forEach ((name ) -> {
706+ if (!props .contains (name )) {
707+ props .setProperty (name , propertyOverrides .getProperty (name ));
708+ }
709+ });
710+ return props ;
711+ }
712+
699713 private void checkGroupInstance (Properties properties , ConsumerFactory <K , V > consumerFactory ) {
700714 String groupInstance = properties .getProperty (ConsumerConfig .GROUP_INSTANCE_ID_CONFIG );
701715 if (!StringUtils .hasText (groupInstance )) {
@@ -755,9 +769,9 @@ else if (timeout instanceof String) {
755769 this .logger .warn (() -> "Unexpected type: " + timeoutToLog .getClass ().getName ()
756770 + " in property '"
757771 + ConsumerConfig .MAX_POLL_INTERVAL_MS_CONFIG
758- + "'; defaulting to 30 seconds ." );
772+ + "'; using Kafka default ." );
759773 }
760- return Duration . ofSeconds ( SIXTY / 2 ). toMillis (); // Default 'max.poll.interval.ms' is 30 seconds
774+ return ( int ) CONSUMER_CONFIG_DEFAULTS . get ( ConsumerConfig . MAX_POLL_INTERVAL_MS_CONFIG );
761775 }
762776 }
763777
@@ -824,12 +838,12 @@ else if (timeout instanceof String) {
824838 this .logger .warn (() -> "Unexpected type: " + timeoutToLog .getClass ().getName ()
825839 + " in property '"
826840 + ConsumerConfig .DEFAULT_API_TIMEOUT_MS_CONFIG
827- + "'; defaulting to 60 seconds for sync commit timeouts" );
841+ + "'; defaulting to Kafka default for sync commit timeouts" );
828842 }
829- return Duration .ofSeconds (SIXTY );
843+ return Duration
844+ .ofMillis ((int ) CONSUMER_CONFIG_DEFAULTS .get (ConsumerConfig .DEFAULT_API_TIMEOUT_MS_CONFIG ));
830845 }
831846 }
832-
833847 }
834848
835849 private Object findDeserializerClass (Map <String , Object > props , boolean isValue ) {
0 commit comments