2017-04-04 48 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该演员系统)

我希望这是有帮助的。