sparkstream接收kafka信息

spark接收kafka发送的消息,本来很简单的,由于不熟的原因,被卡了几个小时。
知道是什么问题的时候简单到哭。

Error:scalac: bad symbolic reference. A signature in KafkaUtils.class refers to term serializer
in package kafka which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling KafkaUtils.class.

下面简单介绍下spark读入kafka:
使用jar包:
kafka_2.10-0.8.2.0-kafka-1.4.0.jar (上面错误是少此包)
spark-streaming-kafka_2.10-1.5.0-cdh5.5.2.jar
kafka-clients-0.8.2.0-kafka-1.4.0.jar
spark-assembly-1.5.1-hadoop2.6.0.jar
datanucleus-rdbms-3.2.9.jar
datanucleus-core-3.2.10.jar
spark-1.5.1-yarn-shuffle.jar
datanucleus-api-jdo-3.2.6.jar
zkclient-0.3.jar
zookeeper-3.4.5-cdh5.5.2.jar
metrics-core-2.2.0.jar

例子非常简单:

object SparkInKafka extends App{

  val zkQuorum = "master:2181"
  val group = "1"
  val topics = "demo"
  val numThreads = 2
  val sparkConf = new SparkConf().setAppName("KafkaWordCount").setMaster("local[2]")
  val ssc =  new StreamingContext(sparkConf, Seconds(20))
  ssc.checkpoint("checkpoint")
  val topicpMap = Map(
    "demo" -> 2
  )
  val lines = KafkaUtils.createStream(ssc, zkQuorum, group, topicpMap)
  lines.saveAsTextFiles("/datafile/steam/log")
  ssc.start()
  ssc.awaitTermination()

}

简单总结下:遇到错误不要放弃,多去尝试多找资料,不经意间就解决了。

你可能感兴趣的:(spark)