2016-09-30 108 views
0

嗨,我是新来的火花和斯卡拉。我试图通过流火花一些鸣叫用下面的代码流:微博Spark执行Streaming

object TwitterStreaming { 

    def main(args: Array[String]): Unit = { 
    if (args.length < 1) { 
     System.err.println("WrongUsage: PropertiesFile, [<filters>]") 
     System.exit(-1) 
    } 

    StreamingExamples.setStreaningLogLevels() 
    val myConfigFile = args(0) 
    val batchInterval_s = 1 
    val fileConfig = ConfigFactory.parseFile(new File(myConfigFile)) 
    val appConf = ConfigFactory.load(fileConfig) 
    // Set the system properties so that Twitter4j library used by twitter stream 
    // can use them to generate OAuth credentials 

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

    val sparkConf = new SparkConf().setAppName("TwitterStreaming").setMaster(appConf.getString("SPARK_MASTER"))//local[2] 

    val ssc = new StreamingContext(sparkConf, Seconds(batchInterval_s)) // creating spark streaming context 
    val stream = TwitterUtils.createStream(ssc, None) 
    val tweet_data = stream.map(status => TweetData(status.getId, "@" + status.getUser.getScreenName, status.getText.trim())) 
    tweet_data.foreachRDD(rdd => { 
     println(s"A sample of tweets I gathered over ${batchInterval_s}s: ${rdd.take(10).mkString(" ")} (total tweets fetched: ${rdd.count()})") 
    }) 
    } 

} 

case class TweetData(id: BigInt, author: String, tweetText: String) 

我的错误:

Exception in thread "main" com.typesafe.config.ConfigException$WrongType:/WorkSpace/InputFiles/application.conf: 5: Cannot concatenate object or list with a non-object-or-list, ConfigString("local") and SimpleConfigList([2]) are not compatible 
at com.typesafe.config.impl.ConfigConcatenation.join(ConfigConcatenation.java:116) 

任何一个可以检查代码,并告诉我哪里做错了吗?

+0

@gsamaras我希望映射到TweetData类......是什么东西错在这样做? – Anji

+0

按照我错误是通过“本地[2]”作为SPARK_MASTER.If是这样的情况下如何设置SPARK_MASTER – Anji

+0

请在您的配置文件(与SPARK_MASTER之一)显示相关行 - 它似乎违反格式预期'typesafe.config'。您可以缩小问题的范围,仅包含文件的内容以及加载配置文件的两行代码 - 这是异常情况,不需要其他所有内容...... –

回答

1

如果您的配置文件包含:

SPARK_MASTER=local[2] 

将其更改为:

SPARK_MASTER="local[2]" 
+0

这很有道理! – gsamaras

+0

@Tzach Zohar更改后,我得到设置SPARK_LOCAL_IP,如果你需要绑定到另一个地址 – Anji

+0

这听起来像是一个其他问题,所以我不能在这里回答。尝试搜索SO/Google,这是Spark的标准内容...与此同时,如果编辑问题以包含所有相关信息和_only_ it - 意味着配置文件条目和代码加载它。 –