I am trying to persist data into database. My persist method is asynchronous.
class MyActor(persistenceFactory:PersistenceFactory) extends Actor {
def receive: Receive = {
case record: Record =>
// this method is asynchronous, immediate return Future[Int]
persistenceFactory.persist(record)
}
}
The bottleneck is here either we get out of memory or no thread available when the application runs under increased load.
So what is the best way to handle asynchronous calls inside receive method of Akka actor ?
This is a great example of when you should have an actor create another actor to handle an interaction. Basically the flow is like this and you can use FSM (finite state machine) too if it makes it easier for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With