akka spray - > akka http migration

这是我的路由器在基于喷雾的服务中的片段:

path(baseUrl / version / "apps" / Segment / "users" / Segment) { (app, user) =>
  respondWithMediaType(MediaTypes.`application/json`) { ctx =>
    createProxy(ctx, management, GetUser(appId = UUID.fromString(app), userId = UUID.fromString(user)))
  }
}

...

def createProxy(ctx: RequestContext, service: ActorRef, message: AnyRef): Unit = {
  val ref = actorRefFactory.actorOf(ResponseProxy.props(ctx))
  service.tell(message, ref)
}

...

object ResponseProxy {
  def props(ctx: RequestContext): Props = Props(new ResponseProxy(ctx))
}

class ResponseProxy(ctx: RequestContext) extends Actor {

  import concurrent.duration._

  context setReceiveTimeout 30.second

  def receive = {
    case ReceiveTimeout =>
      ctx.complete(mapping.mapper.get.writeValueAsString(ResponseMessage("timeout")))
      context stop self

    case x: HttpResponse => ctx.complete(x)

    case x: AnyRef =>
      ctx.complete(mapping.mapper.get.writeValueAsString(x))
      context stop self
  }
}

我尝试在akka http上迁移,这是路由的一部分:

get {
    pathPrefix(baseUrl / version / "apps" / JavaUUID / "users" / JavaUUID ) { (app : UUID , user : UUID) =>
      pathEndOrSingleSlash { ctx =>
        createProxy(ctx, management, GetUser(appId = app, userId = user))
    }
}

我怎么能返回JSON?

基于actor的请求处理没有解决方案吗?只在未来?

回答(0)