Play framework with Akka Throttle for Output

Play framework with Akka Throttle for Output

1 AKKA Version
First of all, check with AKKA version I am using in play framework 2.4.3. I knew the version of AKKA really matters.

In my play framework project
> activator

activator> show compile:dependencyClasspath

It will list all the dependency jars.
akka-actor_2.10-2.3.13.jar

akka-slf4j_2.10-2.3.13.jar

So the version is AKKA 2.3.13.

2 Throttling Actor Messages
Add this in the dependency
  "com.typesafe.akka" %% "akka-contrib" % "2.3.13",

Initiate the Akka as follow
  val contextIOActor = Akka.system.actorOf(ContextIOActor.props, name = "contextio-actor")
  val contextIOThrottler = Akka.system.actorOf(Props(classOf[TimerBasedThrottler], contextio_throttle msgsPer 60.second), name = "conetxt-io-throttler")
  contextIOThrottler ! SetTarget(Some(contextIOActor))

Then all we need to do is to send message to the contextIOThrottler, it will just throttle that and redirect the message to target.

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

你可能感兴趣的:(Play framework with Akka Throttle for Output)