I am working my way through the websocket example and have a question about 
nested streams. Currently I have this: 

import akka.actor.ActorRef
import akka.http.scaladsl.model.ws.{BinaryMessage, TextMessage, Message}
import akka.stream.{OverflowStrategy, FlowShape}
import akka.stream.scaladsl.{Sink, Source, FlowGraph, Flow}

object ChatFlow {
  def apply(userId: Long, channel: Long, rabbitActor: ActorRef): Flow[Message, 
Message, ActorRef] =
    Flow.fromGraph(FlowGraph.create(Source.actorRef[RabbitActor.Message](5, 
OverflowStrategy.fail)) { implicit b =>
      rabbitSource =>
        import FlowGraph.Implicits._

        // for now, ignore all content coming from the websocket
        val fromWebsocket = b.add(Sink.foreach[Message] {
          case TextMessage.Strict(content) => println(content)
//          case bm: BinaryMessage => bm.dataStream.runWith(Sink.ignore)
        })

        // translate rabbit messages into socket messages
        val toWebSocket = b.add(Flow[RabbitActor.Message] map {
          case _ => TextMessage(s"test")
        })

        // when this stream is materialized, register it with rabbitmq
        val websocketMaterialized = b.materializedValue map { actor =>
          RabbitActor.UserJoined(userId, channel, actor)
        }

        val rabbitMQSink = Sink.actorRef[RabbitActor.Message](rabbitActor, 
RabbitActor.UserLeft(userId, channel))

        websocketMaterialized ~> rabbitMQSink
        rabbitSource ~> toWebSocket

        FlowShape(fromWebsocket.inlet, toWebSocket.outlet)
    })
}


My question is about the commented out BinaryMessage. bm.dataStream is a 
Source, and the docs say I should drain this stream to clear the socket. 
How would I do that in this scenario without passing in a materializer?

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to