Skip to content
Advertisement

Sending data to an Akka Stream

I’m attempting to send an ArrayList to an Akka stream for processing. The stream processes the list as follows:

JavaScript

I have defined the code below to try to achieve this result:

JavaScript

Sending data to the stream using : actorRef.tell(Arrays.asList(1,2,3), ActorRef.noSender()); does not appear to have any impact as the result of executing the above code is:

JavaScript

Have I implemented the source correctly?

Advertisement

Answer

I think the first error is that you were sending a list to an actor that expects an Integer, as per the source typing. Send it an integer at a time, e.g.:

JavaScript

Then, fold waits for the source to terminate before emitting its result. You set the actor to expect Done to terminate, but you are sending it Status.Success. Try:

JavaScript

I am not an expert with Akka, but with these 2 modifications, your code yields the expected result (1 + 2 + 3)^2 = 36. You are never stopping the actor system, so the program runs forever, but the principles are there.

Advertisement