Я пишу пакетное задание, чтобы воспроизвести события из Кафки. Кафка v. 0.10.1.0 и искра 1.6.Создание JavaPairRDD с использованием KafkaUtils.createRDD (искра и кафка)
Я пытаюсь использовать JavaPairRDD javaPairRDD = KafkaUtils.createRDD (...) вызов:
Properties configProperties = new Properties();
configProperties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "10.4.1.194:9092");
configProperties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
configProperties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
org.apache.kafka.clients.producer.Producer producer = new KafkaProducer(configProperties);
for (String topic : topicNames) {
List<PartitionInfo> partitionInfos = producer.partitionsFor(topic);
for (PartitionInfo partitionInfo : partitionInfos) {
log.debug("partition leader id: {}", partitionInfo.leader().id());
JavaSparkContext sparkContext = new JavaSparkContext(sparkConf);
Map<String, String> kafkaParams = new HashMap();
kafkaParams.put("metadata.broker.list", "10.4.1.194:9092");
kafkaParams.put("zookeeper.connect", "10.4.1.194:2181");
kafkaParams.put("group.id", "kafka-replay");
OffsetRange[] offsetRanges = new OffsetRange[]{OffsetRange.create(topic, partitionInfo.partition(), 0, Long.MAX_VALUE)};
JavaPairRDD<String, String> javaPairRDD = KafkaUtils.createRDD(
sparkContext,
String.class,
String.class,
StringDecoder.class,
StringDecoder.class,
kafkaParams,
offsetRanges);
javaPairRDD
.map(t -> getInstrEvent(t._2))
.filter(ie -> startTimestamp <= ie.getTimestamp() && ie.getTimestamp() <= endTimestamp)
.foreach(s -> System.out.println(s));
}
}
Однако он терпит неудачу с ошибкой:
2016-12-14 15:45:44,700 [main] ERROR com.goldenrat.analytics.KafkaToHdfsReplayMain - error
org.apache.spark.SparkException: Offsets not available on leader: OffsetRange(topic: 'sfs_create_room', partition: 0, range: [1 -> 100])
at org.apache.spark.streaming.kafka.KafkaUtils$.org$apache$spark$streaming$kaf ka$KafkaUtils$$checkOffsets(KafkaUtils.scala:200)
at org.apache.spark.streaming.kafka.KafkaUtils$$anonfun$createRDD$1.apply(KafkaUtils.scala:253)
at org.apache.spark.streaming.kafka.KafkaUtils$$anonfun$createRDD$1.apply(KafkaUtils.scala:249)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:150)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:111)
at org.apache.spark.SparkContext.withScope(SparkContext.scala:714)
at org.apache.spark.streaming.kafka.KafkaUtils$.createRDD(KafkaUtils.scala:249)
at org.apache.spark.streaming.kafka.KafkaUtils$$anonfun$createRDD$3.apply(KafkaUtils.scala:338)
at org.apache.spark.streaming.kafka.KafkaUtils$$anonfun$createRDD$3.apply(KafkaUtils.scala:333)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:150)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:111)
at org.apache.spark.SparkContext.withScope(SparkContext.scala:714)
at org.apache.spark.streaming.kafka.KafkaUtils$.createRDD(KafkaUtils.scala:333)
at org.apache.spark.streaming.kafka.KafkaUtils.createRDD(KafkaUtils.scala)
at com.goldenrat.analytics.KafkaToHdfsReplayMain$KafkaToHdfsReplayJob.start(KafkaToHdfsReplayMain.java:172)
я могу использовать другие клиенты чтобы связаться с брокером и получить сообщения, поэтому я знаю, что это не брокер. Любая помощь?