=doc add more documentation for WebsocketDirectives and testing
This commit is contained in:
parent
060ea707c9
commit
9399455601
8 changed files with 171 additions and 14 deletions
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
package docs.http.scaladsl.server
|
||||
|
||||
import akka.http.scaladsl.model.ws.BinaryMessage
|
||||
import akka.stream.scaladsl.Sink
|
||||
import org.scalatest.{ Matchers, WordSpec }
|
||||
|
||||
class WebsocketExampleSpec extends WordSpec with Matchers {
|
||||
|
|
@ -27,13 +29,16 @@ class WebsocketExampleSpec extends WordSpec with Matchers {
|
|||
// returns a greeting message for that name
|
||||
val greeterWebsocketService =
|
||||
Flow[Message]
|
||||
.collect {
|
||||
.mapConcat {
|
||||
// we match but don't actually consume the text message here,
|
||||
// rather we simply stream it back as the tail of the response
|
||||
// this means we might start sending the response even before the
|
||||
// end of the incoming message has been received
|
||||
case tm: TextMessage ⇒ TextMessage(Source.single("Hello ") ++ tm.textStream)
|
||||
// ignore binary messages
|
||||
case tm: TextMessage ⇒ TextMessage(Source.single("Hello ") ++ tm.textStream) :: Nil
|
||||
case bm: BinaryMessage =>
|
||||
// ignore binary messages but drain content to avoid the stream being clogged
|
||||
bm.dataStream.runWith(Sink.ignore)
|
||||
Nil
|
||||
}
|
||||
//#websocket-handler
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue