Spark Streaming StreamingContext错误

时间:2015-10-21 10:49:52

标签: scala apache-spark spark-streaming

您好我开始了火花流学习,但我无法运行一个简单的应用程序 我的代码在这里

    import org.apache.spark._
    import org.apache.spark.streaming._
    import org.apache.spark.streaming.StreamingContext._
    val conf = new SparkConf().setMaster("spark://beyhan:7077").setAppName("NetworkWordCount")
    val ssc = new StreamingContext(conf, Seconds(1))
    val lines = ssc.socketTextStream("localhost", 9999)
    val words = lines.flatMap(_.split(" "))

我收到的错误如下:

scala> val newscc = new StreamingContext(conf, Seconds(1))
15/10/21 13:41:18 WARN SparkContext: Another SparkContext is being constructed (or threw an exception in its constructor).  This may indicate an error, since only one SparkContext may be running in this JVM (see SPARK-2243). The other SparkContext was created at:

由于

2 个答案:

答案 0 :(得分:4)

如果您正在使用spark-shell,而且看起来像是这样,则不应使用StreamingContext对象实例化SparkConf,您应该直接传递shell提供的sc

这意味着:

val conf = new SparkConf().setMaster("spark://beyhan:7077").setAppName("NetworkWordCount")
val ssc = new StreamingContext(conf, Seconds(1))

变,

val ssc = new StreamingContext(sc, Seconds(1))

答案 1 :(得分:1)

看起来你在Spark Shell中工作。 已经为您定义了SparkContext,因此您无需创建新的SparkContext。 shell中的SparkContext可用作sc

如果您需要StreamingContext,可以使用现有的SparkContext创建一个:

val ssc = new StreamingContext(sc, Seconds(1))

如果您创建应用程序,则只需要SparkConf和SparkContext。