Skip to content

Instantly share code, notes, and snippets.

@privateblue
Last active December 31, 2015 21:59
Show Gist options
  • Save privateblue/8050540 to your computer and use it in GitHub Desktop.
Save privateblue/8050540 to your computer and use it in GitHub Desktop.
// kinja-service library
trait AdressBook {
val ssoActorPath: String
val inviteActorPath: String
}
class SsoService extends ApiService {
self: AddressBook =>
def authorByToken(token: String): Author = {
lookupAuthorInDatabase(token)
}
}
case class AuthorByToken(token: String)
class SsoActor(ssoService: SsoService) extends Actor {
def receive = {
case AuthorByToken(token) => sender ! ssoService.authorByToken(token)
}
}
class InvitesService extends Service {
self: AddressBook with ActorSystem =>
def invite(token: String, invitee: Author): Unit = {
val ssoActor = actorSystem.actorSelection(ssoActorPath)
val inviter = Await.result(
ssoActor ? AuthorByToken(token),
1 seconds
)
saveInvitationToDatabase(inviter, invitee)
}
}
case class InviteMessage(token: String, invitee: Author)
class InvitesActor(invitesService: InvitesService) extends Actor {
def receive = {
case InviteMessage(token, invitee) => invitesService.invite(token, invitee)
}
}
// kinja-core application
trait ProductionAddressBook extends AddressBook {
val ssoActorPath = "akka.tcp://kinja-core@localhost:2552/user/sso-actor"
val inviteActorPath = "akka.tcp://kinja-core@localhost:2552/user/invites-actor"
}
object SsoService extends service.SsoService with ProductionAddressBook
object InvitesService extends service.InvitesService with ProductionAddressBook with ProductionActorSystem
val ssoActor = akka.actor.ActorSystem("kinja-core").actorOf(Props(new SsoActor(SsoService), "sso-actor"))
val invitesActor = akka.actor.ActorSystem("kinja-core").actorOf(Props(new InvitesActor(InvitesService), "invites-actor"))
// kinja-mantle application
import service.model.InviteMessage
object InvitesApiClient {
def invite(token: String, invitee: Author): Unit = {
val invitesService = context.actorSelection("akka.tcp://kinja-core@localhost:2552/user/invites-actor")
invitesService ! InviteMessage(token, invitee)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment