/*
package com.example.demokafka.util;

import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;

import java.time.Duration;
import java.util.Arrays;

*/
/**
 * @Description
 * @Author ZhouWenTao
 * @Date 2023/9/1 14:05
 *//*

public class Kafka extends Thread {
    Consumer<String, String> consumer116 = new KafkaConsumer<String, String>(KafkaUtil.getSafeConsumerPro());

    @Override
    public void run() {
        poll("sourcetopic");
    }

    public static void main(String[] args) {
        new Kafka().start();
    }

    private void poll(String sourceTopicName) {
        try {
            consumer116.subscribe(Arrays.asList(sourceTopicName));
            while (true) {
                ConsumerRecords<String, String> records = consumer116.poll(5000);
                for (ConsumerRecord<String, String> consumerRecord : records) {
                    String kfkContent = consumerRecord.value();
                    System.out.println("Success to receive kafka :" + kfkContent);
                }
            }
        } catch (Exception e) {
            System.out.println("thread exception:" + e);
        } finally {
            if (consumer116 != null) {
                consumer116.close();
            }
        }
    }

}*/
