简体   繁体   English

Spark Streaming Kafka CreateDirectStream无法解析

[英]Spark Streaming Kafka CreateDirectStream Not Resolving

Need some help, please. 请帮忙。

I am using IntelliJ with SBT to build my apps. 我正在使用IntelliJ和SBT来构建我的应用程序。

I'm working on an app to read a Kafka topic in Spark Streaming in order to do some ETL work on it. 我正在开发一个应用程序来阅读Spark Streaming中的Kafka主题,以便对它进行一些ETL工作。 Unfortunately, I can't read from Kafka. 不幸的是,我无法读取卡夫卡。

The KafkaUtils.createDirectStream isn't resolving and keeps giving me errors (CANNOT RESOLVE SYMBOL). KafkaUtils.createDirectStream没有解析并一直给我错误(无法解析符号)。 I have done my research and it appears I have the correct dependencies. 我做了我的研究,看来我有正确的依赖。

Here is my build.sbt: 这是我的build.sbt:

name := "ASUIStreaming"
version := "0.1"
scalacOptions += "-target:jvm-1.8"
scalaVersion := "2.11.11"

libraryDependencies += "org.apache.spark" %% "spark-core" % "2.1.0"
libraryDependencies += "org.apache.spark" %% "spark-streaming" % "2.1.0"
libraryDependencies += "org.apache.spark" % "spark-streaming-kafka-0-8_2.11" % "2.1.0"
libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.1.0"
libraryDependencies += "org.apache.kafka" %% "kafka-clients" % "0.8.2.1"
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.4"

Any suggestions? 有什么建议么? I should also mention I don't have admin access on the laptop since this is a work computer, and I am using a portable JDK and IntelliJ installation. 我还要提到我在笔记本电脑上没有管理员权限,因为这是一台工作计算机,而且我使用的是便携式JDK和IntelliJ安装。 However, my colleagues at work are in the same situation and it works fine for them. 但是,我工作的同事处于同样的境地,对他们来说效果很好。

Thanks in advance! 提前致谢!

Here is the main Spark Streaming code snippet I'm using. 这是我正在使用的主要Spark Streaming代码片段。 Note : I've masked some of the confidential work data such as IP and Topic name etc. 注意 :我屏蔽了一些机密工作数据,如IP和主题名称等。

import org.apache.kafka.clients.consumer.ConsumerRecord
import kafka.serializer.StringDecoder
import org.apache.spark._
import org.apache.spark.streaming._
import org.apache.spark
import org.apache.kafka.clients.consumer._
import org.apache.kafka.common.serialization.StringDeserializer
import scala.util.parsing.json._
import org.apache.spark.streaming.kafka._



object ASUISpeedKafka extends App

{
  // Create a new Spark Context
  val conf = new SparkConf().setAppName("ASUISpeedKafka").setMaster("local[*]")
  val sc = new SparkContext(conf)
  val ssc = new StreamingContext(sc, Seconds(2))

  //Identify the Kafka Topic and provide the parameters and Topic details
  val kafkaTopic = "TOPIC1"
    val topicsSet = kafkaTopic.split(",").toSet
    val kafkaParams = Map[String, String]
  (

    "metadata.broker.list" -> "IP1:PORT, IP2:PORT2",
    "auto.offset.reset" -> "smallest"
  )

  val kafkaStream = KafkaUtils.createDirectStream[String, String, StringDecoder, StringDecoder]
  (
  ssc, kafkaParams, topicsSet
  )
}

I was able to resolve the issue. 我能够解决这个问题。 After re-creating the project and adding all dependencies again, I found out that in Intellij certain code has to be on the same line other it won't compile. 在重新创建项目并再次添加所有依赖项之后,我发现在Intellij中某些代码必须在同一行上,否则它将无法编译。

In this case, putting val kafkaParams code on the same line (instead of in a code block) solved the issue! 在这种情况下,将val kafkaParams代码放在同一行(而不是代码块)解决了这个问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM