私は以下に定義する以下のアクターを持っています。Akkaの俳優はいつもタイムアウトを待っています
object AuthenticationActor {
def props = Props[AuthenticationActor]
case class LoginUser(id: UUID)
}
class AuthenticationActor @Inject()(cache: CacheApi, userService: UserService) extends Actor{
import AuthenticationActor._
def receive = {
case LoginEmployee(id: UUID) => {
userService.getUserById(id).foreach {
case Some(e) => {
println("Logged user in")
val sessionId = UUID.randomUUID()
cache.set(sessionId.toString, e)
sender() ! Some(e, sessionId)
}
case None => println("No user was found")
}
}
}
}
注:
class EmployeeController @Inject()(@Named("authentication-actor") authActor: ActorRef)(implicit ec: ExecutionContext) extends Controller {
override implicit val timeout: Timeout = 5.seconds
def login(id: UUID) = Action.async { implicit request =>
(authActor ? LoginUser(id)).mapTo[Option[(User, UUID)]].map {
case Some(authInfo) => Ok("Authenticated").withSession(request.session + ("auth" -> authInfo._2.toString))
case None => Forbidden("Not Authenticated")
}
}
}
それにFuture[Option[User]]
そして、次の非常に単純なAPIのCALを返しuserService.getUserById
どちらprintln
呼び出しが実行されますが、login
呼び出しは常に尋ねるが持っていると言って失敗しますタイムアウト。助言がありますか?
あなたは私がmapTo O/pipeToを使用してはならないとの
Future
結果ですか? – Ashalynd