1、我在springboot 整合kafka的项目中设置了自动提交偏移量为false后,发现消息消费后,还是会把偏移量给提交了
首先贴出我的配置:
server:
port: 8080
spring:
kafka:
bootstrap-servers: ip1:9092,ip2:9092,ip3:9092
producer:
retries: 0
batch-size: 16384
buffer-memory: 33554432
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
consumer:
group-id: test-offset-group
auto-offset-reset: earliest
enable-auto-commit: false
auto-commit-interval: 100
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
这是主启动类:
@SpringBootApplication
public class KafkaApplication {
public static void main(String[] args) {
SpringApplication.run(KafkaApplication.class, args);
}
}
下面贴出我的程序代码:
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
/**
* @author 无风三尺浪
*/
@Component
@Slf4j
public class KafkaReceiver {
@KafkaListener(topics = {"test-auto-create-topic"})
public void listen(ConsumerRecord<?, ?> record) {
Optional<?> kafkaMessage = Optional.ofNullable(record.value());
if (kafkaMessage.isPresent()) {
Object o = kafkaMessage.get();
log.info("---------------------record--1 = " + record);
log.info("---------------------message--1 = " + o);
}
}
我程序里并没有手动提交过偏移量。为啥,偏移量会自动提交?