I am trying to throttle my ask
requests to a consumerActor.
val throttler: ActorRef =
Source.actorRef(bufferSize = 1000, OverflowStrategy.dropNew)
.throttle(10, 1.second, 1, ThrottleMode.Shaping)
.to(Sink.foreach[Any](msg => consumerActor ! msg))
.run()
with
aLotOfItems.map(items =>
val itemsFuture = (throttler ? consumeItems(items)).mapTo[Future[String]]
itemsFuture flatMap {x => x}
}).toVector
This does send msgs to the consumerActor but I seem to lose the response as I tried with 2 items but the request just hangs.
I think I need to change the tell
in the Sink.foreach
to an ask or something that can handle a response
Solution: Got it to work using the selected answer below. I had to add
val answer = Source(...) (from the selected answer below)
sender ! answer