Github user rmetzger commented on a diff in the pull request: https://github.com/apache/flink/pull/589#discussion_r28227273 --- Diff: flink-staging/flink-streaming/flink-streaming-connectors/src/main/java/org/apache/flink/streaming/connectors/kafka/api/simple/iterator/KafkaSinglePartitionIterator.java --- @@ -111,18 +128,38 @@ public void initialize() throws InterruptedException { } while (metadata == null); if (metadata.leader() == null) { - throw new RuntimeException("Can't find Leader for Topic and Partition. (at " + hosts.get(0) - + ":" + port); + throw new RuntimeException("Can't find Leader for Topic and Partition. (at " + hosts + ")"); } - leadBroker = metadata.leader().host(); + leadBroker = metadata.leader(); clientName = "Client_" + topic + "_" + partition; - consumer = new SimpleConsumer(leadBroker, port, connectTimeoutMs, bufferSize, clientName); + consumer = new SimpleConsumer(leadBroker.host(), leadBroker.port(), connectTimeoutMs, bufferSize, clientName); + + try { + readOffset = initialOffset.getOffset(consumer, topic, partition, clientName); + } catch (NotLeaderForPartitionException e) { + do { + + metadata = findLeader(hosts, topic, partition); - readOffset = initialOffset.getOffset(consumer, topic, partition, clientName); + try { + Thread.sleep(DEFAULT_WAIT_ON_EMPTY_FETCH); + } catch (InterruptedException ie) { + throw new InterruptedException("Establishing connection to Kafka failed"); + } + } while (metadata == null); --- End diff -- This loop also might run forever
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---