How to check Kafka consumer state
<p>I have Kafka High level consumer. </p>

<pre><code>public class KafkaHighLevelConsumer implements Runnable {
    private final KafkaConsumer&lt;String, String&gt; consumer;
    private final List&lt;String&gt; topics;
    private final int id;

    public KafkaHighLevelConsumer(int id,
                        String groupId,
                        List&lt;String&gt; topics,BlockingQueue&lt;String&gt; storyQueue) {
        this.id = id;
        this.topics = topics;
        Properties props = new Properties();
        props.put("bootstrap.servers", "localhost:9091");
        props.put("group.id", groupId);
        props.put("key.deserializer", StringDeserializer.class.getName());
        props.put("value.deserializer", StringDeserializer.class.getName());
        this.consumer = new KafkaConsumer&lt;&gt;(props);
    }

    @Override
    public void run() {
        try {
            consumer.subscribe(topics);

            while (true) {
                ConsumerRecords&lt;String, String&gt; records = consumer.poll(100);
                for (ConsumerRecord&lt;String, String&gt; record : records) {
                    Map&lt;String, Object&gt; data = new HashMap&lt;&gt;();
                    data.put("partition", record.partition());
                    data.put("offset", record.offset());
                    data.put("value", record.value());
                    System.out.println(this.id + ": " + data);
                }
            }
        } catch (WakeupException e) {
            // ignore for shutdown
        }finally {
            consumer.close();
        }
    }

    public void shutdown() {
        consumer.wakeup();
    }
}
</code></pre>

<p>The consumer works fine, but I need to monitor the state of consumer. 
Why don't we have Exception if server ip or port is incorrect?</p>

<p>If I change port to some incorrect <code>props.put("bootstrap.servers", "localhost:9091");</code> to <code>props.put("bootstrap.servers", "localhost:100500");</code> I still can't get any exception.</p>

<p>I would like to know if I successfully connected to Kafka or not! Is it possible to handle such case?</p>

<p>I use such Maven deps</p>

<pre><code>&lt;dependency&gt;
            &lt;groupId&gt;org.apache.kafka&lt;/groupId&gt;
            &lt;artifactId&gt;kafka-clients&lt;/artifactId&gt;
            &lt;version&gt;0.9.0.1&lt;/version&gt;
        &lt;/dependency&gt;
</code></pre>

<p>Thanks!</p>