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");
        return (String) method.invoke(consumer);
    } catch (Exception ex) {
        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

If I saved your day, you can support me 🤝

Leave a Reply

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