简体   繁体   English

Scala外壳无法识别火花

[英]Scala shell not recognizing spark

I am trying to subscribe to a topic in kafka using scala shell and below is the command that i am executing for the same: 我正在尝试使用scala shell订阅kafka中的一个主题,以下是我为此执行的命令:

scala>val topic1 = spark.read.format("kafka").option("subscribe","topic1").option("kafka.bootstrap.servers", "ip:port,ip2:port,ip3:port").load scala> val topic1 = spark.read.format(“ kafka”)。option(“ subscribe”,“ topic1”)。option(“ kafka.bootstrap.servers”,“ ip:port,ip2:port,ip3:port” )。加载

whenever i execute the command i end up in error as below: 每当我执行命令时,我都会出错,如下所示:

:25: error: not found: value spark Is there any other way i can subscribe to a topic in kafka via scala shell. :25:错误:找不到:值spark还有其他方法可以通过scala shell订阅kafka中的主题。 I am usingSpark - 1.6.3 Scala - 2.10.5 version. 我正在使用Spark-1.6.3 Scala-2.10.5版本。

Spark is not available in standard scala lib, but you can load external libs like spark by adding jar files to classpath fe: Spark在标准scala库中不可用,但是您可以通过将jar文件添加到classpath fe中来加载外部库(例如spark):

scala -cp SomeLib.jar

Or with :require 或与:require

scala> :require SomeLib.jar

And then you will need to import proper package. 然后,您将需要导入适当的软件包。 But question is why? 但是问题是为什么呢? If you want to process that messages somehow then it will be much easier to use some simple project with build tool like SBT. 如果您想以某种方式处理该消息,那么使用带有SBT之类构建工具的简单项目会容易得多。 And if you want just to consume messages fe. 如果您只想使用消息fe。 for some testing / preview and you don't want to build custom app for that, then there is a kafka-console-consumer in Kafka: https://kafka.apache.org/quickstart#quickstart_consume 为了进行一些测试/预览,并且您不想为此创建自定义应用程序,那么卡夫卡中有一个kafka-console-consumerhttps : //kafka.apache.org/quickstart#quickstart_consume

You can use spark-shell which looks exactly like Scala shell but with all necessary libraries available and spark context created. 您可以使用外观类似于Scala shell的spark-shell ,但具有所有必需的库并创建了spark上下文。 spark-shell is included in a standard Spark installation. spark-shell包含在标准Spark安装中。

See eg https://jaceklaskowski.gitbooks.io/mastering-apache-spark/spark-shell.html for details. 有关详细信息,请参见例如https://jaceklaskowski.gitbooks.io/mastering-apache-spark/spark-shell.html

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

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