2017-04-04 47 views
0

我試圖從POST請求中射出火焰,就像Akka文檔中顯示的那樣。 http://doc.akka.io/docs/akka-http/current/scala/http/client-side/request-level.html#request-level-api從Akka的主演獲取上下文

但是,我試圖把它作爲另一個定義的類的內部。如果我嘗試添加任何需要Actor context的信息,例如val http = HTTP(context.system),則會出現錯誤。我如何將上下文傳遞到我試圖從POST請求發出的類中?

trait CustomerProfilesComponent { 
    def customerProfileManager: CustomerService.Async 
} 

object DefaultCustomerProfiles { 
    private case class ProfileUpdateData(path: Seq[String], data: JsObject, metadata: JsObject) 
} 

trait DefaultCustomerProfiles extends CustomerProfilesComponent { 
    self: DatabaseComponent with SourceVersionComponent with ExecutionContextComponent => 

    import DefaultCustomerProfiles._ 

    lazy val customerProfileManager = new CustomerService.Async { 

    import db.api._ 
    import AvroConverter._ 

    override def getVersion : Future[AvroVersion] = { 
     Future.successful(toAvro(sourceVersion)) 
    } 
} 

回答

0

你需要的實際上是一個actor system。從akka-http文檔發佈:

請求級API在ActorSystem內部共享的連接池之上實現。

有用於請求API的兩個使用場景:

  • 使用它within an actor - 當你可以通過演員的場景中獲得的演員系統(如你已經盡力了,但因爲你是不是裏面的演員,你沒有可用的演員上下文)
  • 使用outside an actor你的情況) - 當你可以提供它作爲一個依賴(或者通過類/方法params中,隱含PARAMS該演員系統)

我希望這是有幫助的。