Skip to content

Instantly share code, notes, and snippets.

@abergmeier
Created September 5, 2018 21:53
Show Gist options
  • Save abergmeier/c3a5c550a4674440d726b2a03925e9ec to your computer and use it in GitHub Desktop.
Save abergmeier/c3a5c550a4674440d726b2a03925e9ec to your computer and use it in GitHub Desktop.
Graph
object Login {
def graph(system: ActorSystem, future: Future[LoginCommand.UserData], socketUrl: String) =
Source.fromGraph(GraphDSL.create() { implicit builder: GraphDSL.Builder[NotUsed] =>
val in = Source
.fromFuture(future)
.named("LoginData")
val fanIn = builder.add(Zip[LoginResponse, LoginCommand.UserData].named("LoginDataCollector"))
val exasolLogin = Http(system).webSocketClientFlow(WebSocketRequest(socketUrl)).named("ExasolLogin")
val encryptLoginData = Flow[(LoginResponse, LoginCommand.UserData)].map(data =>
data._2
)
val loginDataMessage = Flow[LoginCommand.UserData].map(data =>
TextMessage("bar")
)
val exasolAnnounce = Http(system).webSocketClientFlow(WebSocketRequest(socketUrl)).named("ExasolAnnounceLogin")
val announceResponse = Flow[Message].map(data =>
LoginResponse("key", "mod", "exp")
)
val loginMessage = Flow[LoginCommand].map(data =>
TextMessage("foo")
)
val session = builder.add(Flow[Message].map(data =>
LoginCommand.SessionData(0, 1, "2", "db", "w", 59, 546, 45, "q", "TZ", "TZB")
).named("ExasolSession"))
import GraphDSL.Implicits._
in ~> fanIn.in1
Source.single(new LoginCommand) ~> loginMessage ~> exasolAnnounce ~> announceResponse ~> fanIn.in0
fanIn.out ~> encryptLoginData ~> loginDataMessage ~> exasolLogin ~> session
SourceShape(session.out)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment