0

Currently, we are using this to send the message to Client

Flow[Message]
  .mapConcat(_ ⇒ Seq.empty[String].toList)
  .merge(source) // Stream the data we want to the client
  .map(data => TextMessage(data))

val source = Source.fromFuture(data).throttle(1, 1.second, 1, ThrottleMode.Shaping).runWith(Sink.ignore)

Now, I want to receive the response from Client and reply back accordingly. How should I do that?

S.K
  • 480
  • 1
  • 4
  • 19

1 Answers1

0

Your WS flow is currently ignoring the incoming message. mapConcat should match the incoming TextMessage or BinaryMessage and respond accordingingly

Flow[Message].mapConcat {
  case tm: TextMessage => TextMessage(Source.single("Hello ") ++ tm.textStream ++ Source.single("!")) :: Nil
  case bm: BinaryMessage =>
    bm.dataStream.runWith(Sink.ignore) // ignore binary message but drain content
    Nil
}
emran
  • 902
  • 6
  • 12