![]() ![]() Anyhow, Akka provides the buffer method with overflow strategies if you need it. The library user doesn’t have to write any explicit back-pressure handling code since it’s built-in into Akka Streams operators. So the back-pressure is a mechanism where downstream components inform upstream components about the number of messages that can be received and buffered.Īkka Streams already has a back-pressure mechanism implemented. Fast source/publisher, slow sink/consumer is a case where we need a back-pressure mechanism since the consumer cannot deal with the rate of messages sent from the producer.Since the throughput of stream elements isn’t constant and the publisher can start emitting elements faster, back-pressure still should be enabled. ![]() Slow source/publisher, fast sink/consumer is ideal because the publisher doesn’t need to slow down message emitting.To explain what back-pressure let’s consider the following two cases: runForeach ( println ) Back-Pressure in a Nutshell Here’s a simple source created from Scala List that contains hashtags. It’s a starting point of every streaming topology any only has output.Ī source can be created from any Scala collection, and it can be a Kafka topic, or it can be made from constantly polling some HTTP endpoint, etc. Source is a component that emits elements asynchronously downstream.So, for designing stream processing topologies with built-in back-pressure, Akka Streams should be considered. Still, it demands a lot of code to implement necessary mechanisms for stream processing workloads like back-pressure, buffering, and transforming data or error-recovery. The tasks like moving and transferring data can be implemented with actors. In this article, the same example will be used to show how Akka Actors can be replaced with a few lines of Akka Streams code. The result of using these modules is boilerplate-free code, which is also less error-prone. The purpose of these modules is to help engineers abstract over low-level actor-based code and focus on business logic. Still, I think it is representative enough to show everything necessary to get started with building actor-based applications.Īctors are the core of Akka toolkit, and they can’t be replaced, but actors back every module in the Akka toolkit. The example I presented is too simple, and using actors to solve that is obliviously overkilling. In the previous article: Parallel processing with Scala and Akka Actors I have explained how to design actor-based applications. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |