spring.kafka.consumer.auto-offset-rest 和 ConsumerConfig.AUTO_OFFSET_RESET_CONFIG 有什么区别?
What is the difference between spring.kafka.consumer.auto-offset-rest and ConsumerConfig.AUTO_OFFSET_RESET_CONFIG?
在 application.properties 中,我有这个:
spring.kafka.consumer.auto-offset-reset=latest
在 KafkaConsumerConfiguration.java 中,我有这个:
@Bean
public Map<String, Object> consumerConfigs(){
Map<String, Object> props = new HashMap<>();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
props.put(ConsumerConfig.GROUP_ID_CONFIG, "group1");
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
return props;
}
我猜他们是一样的?
是一样的。
当为消费者工厂使用 Boot 的自动配置时,属性 映射到 AUTO_OFFSET_RESET_CONFIG
。
The properties supported by auto configuration are shown in Appendix A, Common application properties. Note that, for the most part, these properties (hyphenated or camelCase) map directly to the Apache Kafka dotted properties. Refer to the Apache Kafka documentation for details.
The first few of these properties apply to all components (producers, consumers, admins, and streams) but can be specified at the component level if you wish to use different values. Apache Kafka designates properties with an importance of HIGH, MEDIUM, or LOW. Spring Boot auto-configuration supports all HIGH importance properties, some selected MEDIUM and LOW properties, and any properties that do not have a default value.
Only a subset of the properties supported by Kafka are available directly through the KafkaProperties class. If you wish to configure the producer or consumer with additional properties that are not directly supported, use the following properties: ...
由于您没有使用自动配置(您正在定义自己的配置),因此忽略引导 属性。
在 application.properties 中,我有这个:
spring.kafka.consumer.auto-offset-reset=latest
在 KafkaConsumerConfiguration.java 中,我有这个:
@Bean
public Map<String, Object> consumerConfigs(){
Map<String, Object> props = new HashMap<>();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
props.put(ConsumerConfig.GROUP_ID_CONFIG, "group1");
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
return props;
}
我猜他们是一样的?
是一样的。
当为消费者工厂使用 Boot 的自动配置时,属性 映射到 AUTO_OFFSET_RESET_CONFIG
。
The properties supported by auto configuration are shown in Appendix A, Common application properties. Note that, for the most part, these properties (hyphenated or camelCase) map directly to the Apache Kafka dotted properties. Refer to the Apache Kafka documentation for details.
The first few of these properties apply to all components (producers, consumers, admins, and streams) but can be specified at the component level if you wish to use different values. Apache Kafka designates properties with an importance of HIGH, MEDIUM, or LOW. Spring Boot auto-configuration supports all HIGH importance properties, some selected MEDIUM and LOW properties, and any properties that do not have a default value.
Only a subset of the properties supported by Kafka are available directly through the KafkaProperties class. If you wish to configure the producer or consumer with additional properties that are not directly supported, use the following properties: ...
由于您没有使用自动配置(您正在定义自己的配置),因此忽略引导 属性。