Hi,
I am planning to use Akka Streams in web application. Below is my use case.
Whenever the request come to web server, I will do some operations like stg01, stg02 ...
I have a below questions :- - Do we need to close the streams after each request processed ?
- If N multiple requests come, below invoke method will execute in N times with parallel. In this case, how the actors will create and close ?
Below is the example code snippet :-
implicit val actorSystem = ActorSystem("Example")
implicit val materializer = ActorMaterializer()
implicit val executor = actorSystem.dispatcher
val ll = scala.collection.mutable.ListBuffer[String]()
ll += "123"; ll += "456"; ll += "789"
invoke(ll.toList)
def invoke(customerId: List[String]) {
val source = Source(customerId)
val sink = Sink.foreach[String] { x => display(x) }
val stg01 = Flow[String].map { x => getStg01(x) }
val stg02 = Flow[Int].map { x => getStg02(x) }
val runnable = source via stg01 via stg02 to sink runnable.run }
def getStg01(request: String) = request.toInt
def getStg02(request: Int) = request.toString
def display(request: String) = println(" EVENT ===> " + request)
}