我做了卡夫卡测试,而且效果很好。但是当我在IDE上运行该程序时,出现了此错误,并且不知道如何解决。谁能帮我?非常感谢!
public final class Constants {
public static final String REDIS_SERVER = "localhost";
public static final String KAFKA_SERVER = "localhost";
public static final String KAFKA_ADDR = KAFKA_SERVER + ":9092";
public static final String KAFKA_TOPICS = "recom1";
}
val Array(brokers, topics) = Array(Constants.KAFKA_ADDR, Constants.KAFKA_TOPICS)
val sparkConf = new
SparkConf().setMaster("local[2]").setAppName("RealtimeRecommender")
val ssc = new StreamingContext(sparkConf, Seconds(2))
val topicsSet = topics.split(",").toSet
val kafkaParams = Map[String, String]("metadata.broker.list" -> brokers,"auto.offset.reset" -> "smallest")
val messages = KafkaUtils.createDirectStream[String, String, StringDecoder, StringDecoder](ssc, kafkaParams, topicsSet)
我认为ip和主机名可能不会映射到/ etc / hosts,但是已经有127.0.0.1 localhost。谁能帮我吗?
这是错误:
Exception in thread "main" org.apache.spark.SparkException: java.nio.channels.UnresolvedAddressException
at org.apache.spark.streaming.kafka.KafkaCluster$$anonfun$checkErrors$1.apply(KafkaCluster.scala:366)
at org.apache.spark.streaming.kafka.KafkaCluster$$anonfun$checkErrors$1.apply(KafkaCluster.scala:366)
at scala.util.Either.fold(Either.scala:97)
at org.apache.spark.streaming.kafka.KafkaCluster$.checkErrors(KafkaCluster.scala:365)
at org.apache.spark.streaming.kafka.KafkaUtils$.getFromOffsets(KafkaUtils.scala:222)
at org.apache.spark.streaming.kafka.KafkaUtils$.createDirectStream(KafkaUtils.scala:484)
at com.ssx.recom.realtime.RealtimeRecommender$.main(RealtimeRecommender.scala:26)
at com.ssx.recom.realtime.RealtimeRecommender.main(RealtimeRecommender.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
答案 0 :(得分:0)
我终于解决了这个问题。只需检查zookeeper,因为zookeeper会保存kafka的配置信息,并保存了kafka的主机名。因此IP不起作用!