How to get client id from Kafka Consumer

If you want to read clientid from Kafka Consumer, you may use this method:

private String readConsumerClientId(KafkaConsumer<String, String> consumer) {
    try {
        Method method = consumer.getClass().getDeclaredMethod("getClientId");
        method.setAccessible(true);
        return (String) method.invoke(consumer);
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
Telegram channel

If you still have any questions, feel free to ask me in the comments under this article or write me at promark33@gmail.com.

If I saved your day, you can support me 🤝

Leave a Reply

Your email address will not be published. Required fields are marked *