I have this error in my code (wordCount from Kafka) compiled with SBT
[error] /home/hduser/sbt_project/project1/src/main/scala/sparkKafka.scala:4:35: object kafka is not a member of package org.apache.spark.streaming`
[error] import org.apache.spark.streaming.kafka.KafkaUtils
not found: value KafkaUtils
[error] val lines = KafkaUtils.createStream(ssc, "localhost:2181", "spark-stream ing-consumer-group", Map("customer" -> 2))
The file build.sbt
contains these dependencies:
libraryDependencies += "org.apache.spark" % "spark-core_2.12" % "2.4.0"
libraryDependencies += "org.apache.spark" % "spark-streaming_2.12" % "2.4.0"
libraryDependencies += "org.apache.spark" % "spark-streaming-kafka-0-10_2.12" % "2.4.0"
How can I correctly import KafkaUtils
?
KafkaUtils
is in theorg.apache.spark.streaming.kafka010
package (note that the namespace for the import includes the versionkafka010
).From Spark Streaming Kafka Documentation:
Note: It's usually recommended to use Spark Structured Streaming with Kafka instead.