Play framework with Akka Throttle for Output

本文介绍如何在Playframework 2.4.3中使用Akka 2.3.13版本进行消息限流。通过配置依赖项并初始化Akka Actors实现消息的限制与转发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值