Hi Luc,
On Mon, Jul 27, 2015 at 4:49 PM, Luc Klaassen <
luc.kl...@gmail.com> wrote:
> The connection does not give an error on the client side, but each time a
> message is sent it should print the message server side and then return a
> response with the reversed string. None of this is happening most of the
> time. It simply says the websocket connection is open, and none of the
> messages that are sent are received server-side.
Thanks for confirming. That's not what I observe, for me it seems to work.
However (also, as hinted on the SO issue) your use of `collect` is a
risk as it won't work in all cases. A message is not guaranteed to be
strict, so you may miss streamed messages (see [1]). Try
def websocketActorFlow: Flow[Message, Message, Unit] =
Flow[Message].mapConcat{
case TextMessage.Strict(msg) =>
println(msg)
TextMessage.Strict(msg.reverse) :: Nil
case other: TextMessage =>
println(s"Got other text $other")
other.textStream.runWith(Sink.ignore)
Nil
case other: BinaryMessage =>
println(s"Got other binary $other")
other.dataStream.runWith(Sink.ignore)
Nil
}
and see if you get streamed messages some times. If you get a
non-strict `TextMessage` you either need to handle it in a streaming
fashion or you need to buffer the complete message and only run your
processing, then, on the aggregated string. The second alternative has
the usual risk of using unbounded memory.
That said, I guess that we could need some convenience helpers that
would help with aggregating messages allowing you to specify the
maximum number of characters and maximum duration for which the
aggregation should run per message.
Johannes
[1]
http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0/scala/http/routing-dsl/websocket-support.html#Model