我正在尝试运行一个简单的kafka spark流媒体示例。这是我得到的错误。
16/10/02 20:45:43 INFO SparkEnv:注册OutputCommitCoordinator 线程“main”java.lang.NoSuchMethodError中的异常: 。scala.Predef $ $范围()Lscala / XML / TopScope $;在 org.apache.spark.ui.jobs.StagePage。(StagePage.scala:44)at org.apache.spark.ui.jobs.StagesTab。(StagesTab.scala:34)at at org.apache.spark.ui.SparkUI。(SparkUI.scala:62)at org.apache.spark.ui.SparkUI $ .create(SparkUI.scala:215)at org.apache.spark.ui.SparkUI $ .createLiveUI(SparkUI.scala:157)at at org.apache.spark.SparkContext。(SparkContext.scala:443)at org.apache.spark.streaming.StreamingContext $ .createNewSparkContext(StreamingContext.scala:836) 在 。org.apache.spark.streaming.StreamingContext(StreamingContext.scala:84) 在 。org.apache.spark.streaming.api.java.JavaStreamingContext(JavaStreamingContext.scala:138) 在com.application.SparkConsumer.App.main(App.java:27)
我使用以下pom设置此示例。我试图找到这个缺少的scala.Predef类,并为spark-streaming-kafka-0-8-assembly添加了缺少的依赖项,当我探索这个jar时,我可以看到该类。
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
<version>0.8.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>0.8.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_2.11</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kafka-0-8_2.11</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kafka-0-8-assembly_2.11</artifactId>
<version>2.0.0</version>
</dependency>
我尝试了一个简单的火花字计数示例,它工作正常。当我使用这个spark-streaming-kafka时,我遇到了麻烦。我试图查找此错误,但没有运气。
以下是代码段。
SparkConf sparkConf = new SparkConf().setAppName("someapp").setMaster("local[2]");
// Create the context with 2 seconds batch size
JavaStreamingContext jssc = new JavaStreamingContext(sparkConf, new Duration(2000));
int numThreads = Integer.parseInt(args[3]);
Map<String, Integer> topicMap = new HashMap<String,Integer>();
topicMap.put("fast-messages", 1);
Map<String, String> kafkaParams = new HashMap<String,String>();
kafkaParams.put("metadata.broker.list", "localhost:9092");
JavaPairReceiverInputDStream<String, String> messages =
KafkaUtils.createStream(jssc,"zoo1","my-consumer-group", topicMap);
答案 0 :(得分:0)
当我使用0.8.2.0 kafka的2.11时似乎有问题。切换到2.10后,它工作正常。