0

I'm having a code that executing a pipeline using Akka streams.

My question is what is the best way of scale it out? Can it be done using Akka streams also?

Or it need to be converted into actors/other way?

The code snippet is:

val future = SqsSource(sqsEndpoint)(awsSqsClient)
.takeWhile(_=>true)
.map { m: Message =>
(m, Ack())
}.runWith(SqsAckSink(sqsEndpoint)(awsSqsClient))
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
john
  • 3
  • 3

1 Answers1

0

If you modify your code a bit then your stream will be materialized into multiple Actor values. These materialized Actors will get you the concurrency you are looking for:

val future = 
  SqsSource(sqsEnpoint)(awsSqsClient)           //Actor 1
    .via(Flow[Message] map (m => (m, Ack())))   //Actor 2
    .to(SqsAckSink(sqsEndpoint)(awsSqsClient))  //Actor 3
    .run()

Note the use of via and to. These are important because they indicate that those stages of the stream should be materialized into separate Actors. In your example code you are using map and runWith on the Source which would result in only 1 Actor being created because of operator fusion.

Flows that Ask External Actors

If you're looking to extend to even more Actors then you can use Flow#mapAsync to query an external Actor to do more work, similar to this example.

Ramón J Romero y Vigil
  • 17,373
  • 7
  • 77
  • 125