deprecate TimerBasedThrottler, #22198
This commit is contained in:
parent
bc382afa98
commit
25385e15f2
3 changed files with 60 additions and 0 deletions
|
|
@ -4,6 +4,11 @@ Throttling Actor Messages
|
|||
Introduction
|
||||
------------
|
||||
|
||||
.. warning::
|
||||
**Deprecation warning** - ``TimerBasedThrottler`` has been deprecated and is scheduled for removal
|
||||
in the next major version. Use Akka Streams instead, see
|
||||
:ref:`migration guide <migration-guide-TimerBasedThrottler>`.
|
||||
|
||||
Suppose you are writing an application that makes HTTP requests to an external
|
||||
web service and that this web service has a restriction in place: you may not
|
||||
make more than 10 requests in 1 minute. You will get blocked or need to pay if
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import java.util.concurrent.TimeUnit
|
|||
* @see [[akka.contrib.throttle.Throttler.SetRate]]
|
||||
* @see [[akka.contrib.throttle.Throttler.SetTarget]]
|
||||
*/
|
||||
@deprecated("Use streams, see migration guide", "2.5.0")
|
||||
object Throttler {
|
||||
/**
|
||||
* A rate used for throttling.
|
||||
|
|
@ -214,6 +215,7 @@ private[throttle] object TimerBasedThrottler {
|
|||
*
|
||||
* @see [[akka.contrib.throttle.Throttler]]
|
||||
*/
|
||||
@deprecated("Use streams, see migration guide", "2.5.0")
|
||||
class TimerBasedThrottler(var rate: Rate) extends Actor with FSM[State, Data] {
|
||||
import FSM.`→`
|
||||
|
||||
|
|
|
|||
|
|
@ -575,6 +575,59 @@ PeekMailbox
|
|||
|
||||
``PeekMailbox`` is deprecated. Use an explicit supervisor or proxy actor instead.
|
||||
|
||||
.. _migration-guide-TimerBasedThrottler:
|
||||
|
||||
TimerBasedThrottler
|
||||
-------------------
|
||||
|
||||
``TimerBasedThrottler`` is deprecated. Use the ``throttle`` stage in Akka Streams instead.
|
||||
|
||||
Example in Scala::
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import akka.NotUsed
|
||||
import akka.actor.ActorRef
|
||||
import akka.actor.ActorSystem
|
||||
import akka.stream.ActorMaterializer
|
||||
import akka.stream.OverflowStrategy
|
||||
import akka.stream.ThrottleMode
|
||||
import akka.stream.scaladsl.Sink
|
||||
import akka.stream.scaladsl.Source
|
||||
|
||||
val system: ActorSystem = ??? // TODO real ActorSystem here
|
||||
val target: ActorRef = ??? // TODO real target ActorRef here
|
||||
implicit val materializer = ActorMaterializer.create(system)
|
||||
|
||||
val throttler: ActorRef =
|
||||
Source.actorRef(bufferSize = 1000, OverflowStrategy.dropNew)
|
||||
.throttle(100, 1.second, 10, ThrottleMode.Shaping)
|
||||
.to(Sink.actorRef(target, NotUsed))
|
||||
.run()
|
||||
|
||||
Example in Java::
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.ActorMaterializer;
|
||||
import akka.stream.Materializer;
|
||||
import akka.stream.OverflowStrategy;
|
||||
import akka.stream.ThrottleMode;
|
||||
import akka.stream.javadsl.Sink;
|
||||
import akka.stream.javadsl.Source;
|
||||
|
||||
final ActorSystem system = null; // TODO real ActorSystem here
|
||||
final ActorRef target = null; // TODO real target ActorRef here
|
||||
final Materializer materializer = ActorMaterializer.create(system);
|
||||
|
||||
final ActorRef throttler =
|
||||
Source.actorRef(1000, OverflowStrategy.dropNew())
|
||||
.throttle(100, FiniteDuration.create(1, TimeUnit.SECONDS), 10, ThrottleMode.shaping())
|
||||
.to(Sink.actorRef(target, NotUsed.getInstance()))
|
||||
.run(materializer);
|
||||
|
||||
Akka Typed
|
||||
==========
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue