λ Allquantor λ
λ Allquantor λ

Reputation: 1131

How to slow down the producer in Akka-Streams

I"m trying to solve a problem with akka-streams. I want that my initial producer continuously fetch a queue/mongodb collection and do it within a configured interval. What is a common practice to realize it?

Upvotes: 4

Views: 739

Answers (2)

λ Allquantor λ
λ Allquantor λ

Reputation: 1131

Additionally, there is a concept called throttle. It can be used as follow:

Source(...).throttle(50, 1.second, 1, ThrottleMode.Shaping)

It allows you to specify a fetching interval e.g above 50 items per second. An example can be found in the documentation here: http://doc.akka.io/docs/akka/current/scala/stream/stream-quickstart.html#Time-Based_Processing

Upvotes: 2

Rüdiger Klaehn
Rüdiger Klaehn

Reputation: 12565

You mean at a fixed time interval?

Start with Source.tick(...).map(loadFromMongo)?

Put in a conflate that drops ticks to prevent querying the db more often than downstream can handle, if that is what you want.

Upvotes: 4

Related Questions