Kafka发布订阅模式和手动提交模式

   @KafkaListener(topics = "liuzq.test.kafka.topic",groupId = "1")
    public void test1(ConsumerRecord record, Acknowledgment ack) {
        String value = record.value();
        System.out.println("test1"+value);
    }

    @KafkaListener(topics = "liuzq.test.kafka.topic",groupId = "2")
    public void test2(ConsumerRecord record, Acknowledgment ack) {
        String value = record.value();
        System.out.println("test2"+value);
    }

监听者的 groupId不同 kafka发送的消息会被者两个监听者同时监听消费

 

kafka配置

spring.kafka.bootstrap-servers=tsp-dev-kafka.beantechyun.cn:9092
spring.kafka.consumer.group-id=cpsp
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer

spring.kafka.consumer.enable-auto-commit=false
spring.kafka.listener.ack-mode=manual
spring.kafka.listener.concurrency=10
##用户退车
spring.kafka.topic.vehicle-owner-unbind-vehicle=vehicle-owner-unbind-vehicle

手动提交ack配置

spring.kafka.consumer.enable-auto-commit=false
spring.kafka.listener.ack-mode=manual

 

你可能感兴趣的:(javaweb,kafka)