Created
October 11, 2016 07:43
-
-
Save ane/6afa45e2ab1eb2ab97222b1537bc2bb5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val end: Sink[Foo, NotUsed] = ??? | |
val route = Flow.fromGraph(GraphDSL.create(end) { implicit builder => dest => | |
import GraphDSL.Implicits._ | |
// todo: errors, request validation, etc. | |
val entityFlow = builder.add(Flow[HttpRequest].mapAsync(1)(r => Unmarshal(r.entity).to[Foo])) | |
val responseFlow = builder.add(Flow[Foo].map(_ => HttpResponse(StatusCodes.Created))) | |
val bcast = builder.add(Broadcast[Foo](2)) | |
entityFlow.out ~> bcast.in | |
bcast.out(0) ~> dest.in | |
bcast.out(1) ~> responseFlow.in | |
FlowShape(entityFlow.in, responseFlow.out) | |
}) | |
Http().bindAndHandle(route, "localhost", 8080) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment