[ 
https://issues.apache.org/jira/browse/KAFKA-15686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17780843#comment-17780843
 ] 

Jiahongchao commented on KAFKA-15686:
-------------------------------------

Hi, [~pnee] , in the following code, even if the broker is unreachable, 
consumer.poll alway return an empty result instead of throwing an exception. So 
users will not know if the topic has no message or if the broker is down, we 
need to check log looking for something like "WARN clients.NetworkClient: 
[Consumer clientId=consumer-3, groupId=JAVA] Connection to node -1 could not be 
established. Broker may not be available"
{code:java}
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9094");
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, 
"org.apache.kafka.common.serialization.StringDeserializer");
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, 
"org.apache.kafka.common.serialization.StringDeserializer");
props.put(ConsumerConfig.GROUP_ID_CONFIG, "test-consumer-group");
try (KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props)) {
    consumer.subscribe(List.of("bar"));
    while (true) {
        ConsumerRecords<String, String> records = 
consumer.poll(Duration.ofMillis(100));
        System.out.println(records.count());
    }
}{code}

> Consumer should be able to detect network problem
> -------------------------------------------------
>
>                 Key: KAFKA-15686
>                 URL: https://issues.apache.org/jira/browse/KAFKA-15686
>             Project: Kafka
>          Issue Type: New Feature
>          Components: consumer
>    Affects Versions: 3.5.0
>            Reporter: Jiahongchao
>            Priority: Minor
>
> When we call poll method in consumer, it will return normally even if some 
> partitions do not have a leader.
> What should we do to detect such failures? Currently we have to check log to 
> find out broker connection problem.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to