я пытаюсь подключить мою структурированную потоковую искру 2.4.5 с kafka, но все время, когда я пытаюсь использовать этот источник данных, возникает ошибка. Следуйте моему scala коду и моей сборке sbt:
import org.apache.spark.sql._
import org.apache.spark.sql.types._
import org.apache.spark.sql.functions._
import org.apache.spark.sql.streaming.Trigger
object streaming_app_demo {
def main(args: Array[String]): Unit = {
println("Spark Structured Streaming with Kafka Demo Application Started ...")
val KAFKA_TOPIC_NAME_CONS = "test"
val KAFKA_OUTPUT_TOPIC_NAME_CONS = "test"
val KAFKA_BOOTSTRAP_SERVERS_CONS = "localhost:9092"
val spark = SparkSession.builder
.master("local[*]")
.appName("Spark Structured Streaming with Kafka Demo")
.getOrCreate()
spark.sparkContext.setLogLevel("ERROR")
// Stream from Kafka
val df = spark.readStream
.format("kafka")
.option("kafka.bootstrap.servers", KAFKA_BOOTSTRAP_SERVERS_CONS)
.option("subscribe", KAFKA_TOPIC_NAME_CONS)
.option("startingOffsets", "latest")
.load()
val ds = df
.selectExpr("CAST(key AS STRING)", "CAST(value AS STRING)")
.writeStream
.format("kafka")
.option("kafka.bootstrap.servers", "localhost:9092")
.option("topic", "test2")
.start()
}
}
И ошибка:
Exception in thread "main" org.apache.spark.sql.AnalysisException: Failed to find data source: kafka. Please deploy the application as per the deployment section of "Structured Streaming + Kafka Integration Guide".;
at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:652)
at org.apache.spark.sql.streaming.DataStreamReader.load(DataStreamReader.scala:161)
at streaming_app_demo$.main(teste.scala:29)
at streaming_app_demo.main(teste.scala)
И мой sbt.build:
name := "scala_212"
version := "0.1"
scalaVersion := "2.12.11"
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.4.5"
libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.4.5"
libraryDependencies += "org.apache.spark" %% "spark-sql-kafka-0-10" % "2.4.5" % "provided"
libraryDependencies += "org.apache.kafka" % "kafka-clients" % "2.5.0"
Спасибо!