Is there a way to split an Akka stream? My use case is downloading a file from a http URL on GET request and then streaming it to the client as as well as a local file.
Hi,
You would need to create a graph as described in https://doc.akka.io/docs/akka/current/stream/stream-graphs.html, similar to this:
val g = RunnableGraph.fromGraph(GraphDSL.create() { implicit builder: GraphDSL.Builder[NotUsed] =>
import GraphDSL.Implicits._
val in = Source(1 to 10)
val out = Sink.ignore
val bcast = builder.add(Broadcast[Int](2))
val merge = builder.add(Merge[Int](2))
val f1, f2, f3, f4 = Flow[Int].map(_ + 10)
in ~> f1 ~> bcast ~> f2 ~> merge ~> f3 ~> out
bcast ~> f4 ~> merge
ClosedShape
})
Idea would be broadcast your incoming file into two ports, instead of merge you can use two sinks to consume elements.
Regards,
Syed Farhan Ali