Created
July 27, 2014 23:59
-
-
Save j14159/ca191b61a73382316f9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait PersonClient { | |
// supply a router with a pool of PersonDao: | |
val personPool: ActorRef | |
// how long should we wait for a response from PersonDao: | |
val timeoutInMillis: Long | |
implicit val timeout = Timeout(timeoutInMillis millis) | |
def addPerson(p: Person): Future[Int] = | |
(personPool ? p).mapTo[Int] | |
def personById(id: Long): Future[Person] = | |
(personPool ? PersonById).mapTo[Person] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice. I had some ideas on this kind of architecure here. Currently I'm trying this idea and found some edges to think about
Timeouts
Should I use a global
timeout
like you, or add it as an implicit parameter for each method, so the caller can decideActorRef or ActorSelection
ActorRef
orActorSelection
? When I'm using a cluster, I configure cluster aware routers and just implement like a "dummy actor"However if you want to reuse a local service directly an
ActorSelection
maybeeasier (not 100% sure about that)
Direct Usage of API
If I build services on top of other services, you can use the message api directly to have full control of dispatchers/flow-control/async-stuff
E.g