Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add kafka autoStartUp false in the ConsumerConfig

how to add kafka property autoStartUp false manualy at property lvl ? what i mean, for example i can do it like that:

@KafkaListener(autoStartUp = "false")

but i wanna do it in the ConsumerProperties, in the own BeanPostProcessor. I could't find this property in the ConsumerProperties for example:

Map<String, Object> props = new HashMap<>();

    props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, this.kafkaConfig.getBootstrapServers());
    props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
    props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
    //here i need to add autoStartUp to false
like image 689
MikeM Avatar asked Dec 14 '25 07:12

MikeM


1 Answers

The autoStartup has nothing to do with Apache Kafka. It is native Spring container feature: https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-factory-lifecycle-processor. So, even if it would be possible via your props, it would not sound reasonable and felt more like abusing of Apache Kafka config with options which are not going to be parsed by Kafka mechanisms.

What you need is really pay more attention to that autoStartup option JavaDocs:

/**
 * Set to true or false, to override the default setting in the container factory. May
 * be a property placeholder or SpEL expression that evaluates to a {@link Boolean} or
 * a {@link String}, in which case the {@link Boolean#parseBoolean(String)} is used to
 * obtain the value.
 * <p>SpEL {@code #{...}} and property place holders {@code ${...}} are supported.
 * @return true to auto start, false to not auto start.
 * @since 2.2
 */
String autoStartup() default "";

and look more in the Docs: https://docs.spring.io/spring-kafka/docs/2.6.2/reference/html/#kafka-listener-annotation

So, roughly speaking, if you add an autoStartUp into your props bean, you can configure your @KafkaListener like this:

@KafkaListener(autoStartUp = "#{props.autoStartUp}")
like image 108
Artem Bilan Avatar answered Dec 16 '25 23:12

Artem Bilan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!