Hi

I have a flow that I want to conditionally branch off to either one of two 
other flows. Basically I'm looking to "flatMap that shit", but how do I do 
this in the context of Akka streams?

In my current attempt the types will not line up in the flatten step, I get 
the compile error:

polymorphic expression cannot be instantiated to expected type;
[error]  found   : 
[T]akka.stream.FlattenStrategy[akka.stream.scaladsl.Source[T],T]
[error]  required: 
akka.stream.FlattenStrategy[akka.stream.scaladsl.Flow[akka.http.model.HttpRequest,akka.http.model.HttpResponse],?]
[error]       }.flatten( FlattenStrategy.concat )

Relevant code:

val serverBinding = Http( systemRef ).
  bind(
    interface = interface,
    port = port )

val con: OutgoingConnection = Http( systemRef ).outgoingConnection( "akka.io" )

val badRequestFlow: Flow[HttpRequest, HttpResponse] =
  Flow[HttpRequest].map( _ ⇒ HttpResponse( BadRequest, entity = "Bad Request" ) 
)

val proxy: Flow[HttpRequest, HttpResponse] = con.flow.concat( Source( () ⇒ 
List( HttpRequest( GET, uri = "/" ) ).iterator ) )

val proxyRequest: Flow[HttpRequest, HttpResponse] =
  Flow[HttpRequest].map {
    case HttpRequest( POST, Uri.Path( "/proxy" ), _, _, _ ) ⇒ proxy
    case other ⇒ badRequestFlow
  }.flatten( FlattenStrategy.concat )

Any hints or examples warmly welcome! 
I'm also wondering about supervision of flows (for error handling) but I 
will put that in a separate post.

/Magnus

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to