I have read that an important rule when using Akka is avoiding any blocking input/output operations, polling, busy waiting, sleeping, etc. But what if I really need some flow control?
I am using Akka actors to send mail to our customers, and to be friendly to the mail server, send one mail per 5 second. My plan is using a dispatcher actor to do the flow control and a sender actor to do the mail sending work.
class Dispatcher extends Actor {
def receive = {
case ResetPassword(to, data) =>
senderActor ! Mail("resetPassword", to, data)
Thread.sleep(5000)
...
}
}
class Sender extends Actor {
def receive = {
case Mail(to, data) => // send the mail immediately
...
}
}
Is this the right way to go? If not, how should I do the flow control?