在 ConsumerConfig 中添加 kafka autoStartUp false
add kafka autoStartUp false in the ConsumerConfig
如何在 属性 lvl 手动添加 kafka 属性 autoStartUp false?我的意思是,例如我可以这样做:
@KafkaListener(autoStartUp = "false")
但我想在自己的 BeanPostProcessor 中的 ConsumerProperties 中执行此操作。例如,我无法在 ConsumerProperties 中找到此 属性:
Map 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
autoStartup
与Apache Kafka无关。它是本机 Spring 容器功能:https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-factory-lifecycle-processor。因此,即使可以通过您的 props
实现,这听起来也不合理,感觉更像是滥用 Apache Kafka 配置以及不会被 Kafka 机制解析的选项。
您真正需要的是更加注意 autoStartup
选项 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 "";
并在文档中查看更多信息:https://docs.spring.io/spring-kafka/docs/2.6.2/reference/html/#kafka-listener-annotation
所以,粗略地说,如果将 autoStartUp
添加到 props
bean 中,则可以像这样配置 @KafkaListener
:
@KafkaListener(autoStartUp = "#{props.autoStartUp}")
如何在 属性 lvl 手动添加 kafka 属性 autoStartUp false?我的意思是,例如我可以这样做:
@KafkaListener(autoStartUp = "false")
但我想在自己的 BeanPostProcessor 中的 ConsumerProperties 中执行此操作。例如,我无法在 ConsumerProperties 中找到此 属性:
Map
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
autoStartup
与Apache Kafka无关。它是本机 Spring 容器功能:https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-factory-lifecycle-processor。因此,即使可以通过您的 props
实现,这听起来也不合理,感觉更像是滥用 Apache Kafka 配置以及不会被 Kafka 机制解析的选项。
您真正需要的是更加注意 autoStartup
选项 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 "";
并在文档中查看更多信息:https://docs.spring.io/spring-kafka/docs/2.6.2/reference/html/#kafka-listener-annotation
所以,粗略地说,如果将 autoStartUp
添加到 props
bean 中,则可以像这样配置 @KafkaListener
:
@KafkaListener(autoStartUp = "#{props.autoStartUp}")