How it works...
In this recipe, we covered how to use a throttler actor to control the rate of the message coming out. Akka provides a timer-based throttler in the akka-contrib module that helps you control the rate by passing a Rate object. In our example, we are implicitly defining our rate of two messages per second by giving 2 msgsPer 1.second when creating the throttler actor. After instantiating, we need to initialize the throttler by setting the target actor. In our case, we do this by sending a message to the throttler with the message SetTarget. To verify that all is working as expected, we run the application and then we can see that for any given second, there are only two messages received.
Meanwhile, this implementation throttles ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access