2014-10-11 62 views
1

我的意圖是使用Akka創建應用程序。一旦我意識到我需要創建一些Web服務,我決定使用Spray。使用Spark(MLlib)和Spray:如何整合兩者?

這個應用程序需要一個分類器,所以我在Spark上用MLlib構建了一個原型。現在我需要了解如何將Spark與Spray集成。具體來說,我需要得到
1.這是創建星火語境
2.如何使火花背景下可見的演員

我假設我要創建而引導星火背景下,最好的辦法該應用程序,所以我修改了GitHub的示例中的代碼,該示例適用於沒有Spark集成的Spray應用程序。因此,我實例化演員

14/10/11 22:12:32 ERROR actor.OneForOneStrategy: exception during creation 
akka.actor.ActorInitializationException: exception during creation 

我改變原來代碼標有//$$$ $$$

trait Core { 

    protected implicit def system: ActorSystem 
    // $$$ SparkContext in the trait $$$ 
    protected implicit def sc: SparkContext 

} 

/** 
* This trait implements ``Core`` by starting the required 
* ``ActorSystem`` and registering the 
* termination handler to stop the system when the JVM exits. 
*/ 
trait BootedCore extends Core with Api { 
    def system: ActorSystem = ActorSystem("activator-akka-spray") 
    def actorRefFactory: ActorRefFactory = system 
    // $$$ Initializing SparkContext $$$ 
    def sc = new SparkContext("local[2]", "naivebayes") 

    val rootService = system.actorOf(Props(new RoutedHttpService(routes))) 

    IO(Http)(system) ! Http.Bind(rootService, "0.0.0.0", port = 9010) 

    /** 
    * Construct the ActorSystem we will use in our application 
    */ 
    //protected implicit val system : ActorSystem 

    /** 
    * Ensure that the constructed ActorSystem is shut 
    * down when the JVM shuts down 
    */ 
    sys.addShutdownHook(system.shutdown()) 

} 

/** 
* This trait contains the actors that make up our application; 
* it can be mixed in with 
* ``BootedCore`` for running code or ``TestKit`` 
* for unit and integration tests. 
*/ 
trait CoreActors { 
    this: Core => 
          //$$$ passing the context to the actor $$$ 
    val classifier = system.actorOf(Props(classOf[ClassifierActor], sc)) 

} 

回答

3

我剛剛發現了不同的版本阿卡錯誤是由於當得到一個錯誤由Spark和Spray使用。

== == UPDATE
如果我沒有錯,問題只是從我的項目依賴於build.sbt消除阿卡這樣我就可以使用特定的阿卡版本星火依賴於固定的。 我只是讓Spark爲我選擇要使用的Akka版本。 然後我搜索了一個取決於Spark所依賴的相同版本的Akka的噴霧版本。

星火1.1.0
噴霧1.2.2

我從來沒有更新到較早版本,所以我不能說這兩個版本都可以配合在一起,如果你要熬夜到最新。

+0

能否請你說明你是如何解決這個問題的(git回購會很棒,但即使版本也會有所幫助) - 我遇到了同樣的問題。我嘗試與val akkaVersion =「2.3.9」 val sprayVersion =「1.2-20130727」 val sparkVersion =「1.2.1」但包括火花瓶後,我得到像java.lang.NoSuchMethodError錯誤:akka.actor .Props $。適用(Lscala/Function0;)拉卡/演員/道具; – 2015-05-01 02:36:08

+0

我剛剛更新了以前的帖子。希望它有幫助 – Max 2015-05-01 13:25:07

+0

你有上面的git回購嗎?我正在做類似的工作 - 將Spark與Spark整合在一起,我不知道如何去做。謝謝 – 2016-11-01 16:48:24