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;
    }
}

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

Leave a Reply

Your email address will not be published.