I have an akka http web socket Route
with a code similar to:
private val wsReader: Route = path("v1" / "data" / "ws") { log.info("Opening websocket connecting ...")
val testSource = Source
.repeat("Hello")
.throttle(1, 1.seconds)
.map(x => {
println(x)
x
})
.map(TextMessage.Strict)
.limit(1000)
extractUpgradeToWebSocket { upgrade ⇒
complete(upgrade.handleMessagesWithSinkSource(Sink.ignore, testSource))
}
}
Everything works fine (I receive from the client 1 test message every second). The only problem is that I don't understand how to stop/close the Source
(testSource
) if the client close the web socket connection.
You can see that the source continue to produce elements (see println
) also if the web socket is down.
How can I detect a client disconnection?