cjl
2023-11-15 d117d3af15dddc4f07baffa8b5bf6b727c05de7c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.moral.api.exception.consumer;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
@Component
@Slf4j
public class KafkaConsumer {
 
/*    *//**
     * 这是手动提交的消费方式
     * @param record
     * @param ack
     * @throws Exception
     *//*
    @KafkaListener(topics = TopicConstants.TEST_TOPIC_MESSAGE,groupId = "test")
    public void listenTest(ConsumerRecord<String, String> record , Acknowledgment ack) throws Exception {
        String msg = record.value();
        System.out.println(msg);
        if (new Random().nextInt(100)<50){
            log.info(String.format("kafka 消费消息成功---------------- listen1 topic = %s, offset = %d, value = %s ", record.topic(), record.offset(), record.value()));
            ack.acknowledge();
        }
    }*/
}