package com.citygis.web.utils;

import com.alibaba.fastjson2.JSONObject;
import org.apache.kafka.clients.admin.AdminClient;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @Package com.shcd.utils
 * @Author zyl
 * @Date 2024/5/29 0029 17:06
 * @description:
 */
@Component
public class KafkaUtil {
    public static String comparingByName(JSONObject jo) {
        return jo.getString("topic");
    }

    public static Integer comparingByPartition(JSONObject jo) {
        return jo.getInteger("partition");
    }



    /**
     * get all topics' name, connection test
     * @param adminClient
     * @return topics' name set
     */
    public static Set<String> kafkaConnectTest(AdminClient adminClient) {
        try {
            return adminClient.listTopics().names().get();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
