【问题标题】:Spark, Scala, Streaming TwitterSpark、Scala、流式 Twitter
【发布时间】:2016-10-28 15:37:04
【问题描述】:

我在 Ubuntu 主路径中编写了一个 scala 脚本作为 abc.scala 并硬编码来自 twitter 应用程序的所有 oauth 值:

import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.SparkContext._
import org.apache.spark.streaming.twitter._
import org.apache.spark.SparkConf

System.setProperty("twitter4j.oauth.consumerKey", consumerKey)
System.setProperty("twitter4j.oauth.consumerSecret", consumerSecret)
System.setProperty("twitter4j.oauth.accessToken", accessToken)
System.setProperty("twitter4j.oauth.accessTokenSecret", accessTokenSecret)

val filters="Raj"
val sparkConf = new SparkConf().setAppName("TwitterPopularTags").setMaster("local[2]")
val ssc = new StreamingContext(sparkConf, Seconds(2))
val stream = TwitterUtils.createStream(ssc, None, filters)

我执行的是

$Spark_bin-2.7> cat abc.scala | ./spark-shell

它一直运行到 StreamingContext。但是当它到达 TwitterUtils 时,它会给出错误读取:

错误:未找到:TwitterUtils

我下载了最新的 Spark 2.0.1。可以一步一步指出设置或文档吗?

【问题讨论】:

  • 你添加了twitter流的依赖吗?
  • 你有我可以添加依赖的步骤吗?在Linux(Ubuntu 16.1)上运行阅读Twitter(spark 2.0.1),Scala 2.11.8,Java 8的Spark应用程序给我一个错误:它给出了错误--- java.lang.NoClassDefFoundError:org/apache/spark/Logging我也尝试了所有 4 个参数、过滤器、DISK_ONLY_2,但它不起作用并在 TwitterUtils.createStream() raja@ubuntu:/usr/local/spark/bin$ cat twitter_script|spark-shell --packages org.apache.spark 上抱怨: spark-streaming-twitter_2.11:1.6.1

标签: scala twitter apache-spark streaming


【解决方案1】:

将 org.apache.spark:spark-streaming-twitter_2.11:1.6.1 添加到 spark-shell 中

$Spark_bin-2.7> cat abc.scala | ./spark-shell --packages org.apache.spark:spark-streaming-twitter_2.11:1.6.1

使用这种方法

import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.SparkContext._
import org.apache.spark.streaming.twitter._
import org.apache.spark.SparkConf

System.setProperty("twitter4j.oauth.consumerKey", consumerKey)
System.setProperty("twitter4j.oauth.consumerSecret", consumerSecret)
System.setProperty("twitter4j.oauth.accessToken", accessToken)
System.setProperty("twitter4j.oauth.accessTokenSecret", accessTokenSecret)

sc.stop()
val filters="Raj"
val sparkConf = new SparkConf().setAppName("TwitterPopularTags").setMaster("local[2]")
val sc = new SparkContext(sparkConf)
val ssc = new StreamingContext(sc, Seconds(2))
val stream = TwitterUtils.createStream(ssc, None, filters)

【讨论】:

    猜你喜欢
    • 2019-03-05
    • 2016-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多