jiexray 2015-11-21
PlayframeworkwithAkkaThrottleforOutput
1AKKAVersion
Firstofall,checkwithAKKAversionIamusinginplayframework2.4.3.IknewtheversionofAKKAreallymatters.
Inmyplayframeworkproject
>activator
activator>showcompile:dependencyClasspath
Itwilllistallthedependencyjars.
akka-actor_2.10-2.3.13.jar
akka-slf4j_2.10-2.3.13.jar
SotheversionisAKKA2.3.13.
2ThrottlingActorMessages
Addthisinthedependency
"com.typesafe.akka"%%"akka-contrib"%"2.3.13",
InitiatetheAkkaasfollow
valcontextIOActor=Akka.system.actorOf(ContextIOActor.props,name="contextio-actor")
valcontextIOThrottler=Akka.system.actorOf(Props(classOf[TimerBasedThrottler],contextio_throttlemsgsPer60.second),name="conetxt-io-throttler")
contextIOThrottler!SetTarget(Some(contextIOActor))
ThenallweneedtodoistosendmessagetothecontextIOThrottler,itwilljustthrottlethatandredirectthemessagetotarget.
References:
http://stackoverflow.com/questions/31112397/print-akka-version-in-play-framework-2-4-1
http://doc.akka.io/docs/akka/2.3.13/contrib/throttle.html
http://letitcrash.com/post/28901663062/throttling-messages-in-akka-2
http://www.michaelpollmeier.com/akka-work-pulling-pattern/
http://www.michaelpollmeier.com/akka-work-pulling-pattern-to-throttle-work/
http://doc.akka.io/api/akka/2.3.13/index.html#akka.contrib.throttle.TimerBasedThrottler
https://github.com/jonasanso/throttling/blob/5102d35f9abdf0cb15732a1cef0e4c92c4cca59c/app/controllers/Application.scala