Hi Endre,
 
many thanks for the advice. After updating to 2.0.M1 it works nicely.
 
However, I struggle with two more issues:
 
1. How can I react on the event that the web socket is closed? Should I simply watch for the death of the actor whose ActorRef is registered with the UpdateActor?
2. It seems that the flow is terminated after some time of inactivity. How can I ensure that it stays on hold? (I found that using Flow.keepAlive prevents the flow from terminating, but also causes that the specified keep alive message will be delivered to the browser.)
 
TIA
 
Stefan
 
Gesendet: Dienstag, 24. November 2015 um 17:28 Uhr
Von: "Akka Team" <[email protected]>
An: "Akka User List" <[email protected]>
Betreff: Re: [akka-user] How to pipe reactive mongo results into a WebSocket stream
Hi Stefan,
 
I want to use a web socket connection
 
1. to push periodically results from the server to the browser
 
2. to send requests from the browser to the server and return the corresponding results to the browser (there might be many results, therefore the results should be streamed into the web socket connection)
 

Flow[Message]
  // Take message as text
  .collect {
    case tm: TextMessage => tm
    case _ => throw new UnsupportedOperationException("binary is not supported")
  }
  // Produce a MongoDB publisher somehow
  .map{msg.textStream. ... }
  // Make a Source from the publisher and feed into this stream
  .flatMapConcat(Source(_))
  // Wrap in websocket Text message
  .map(TextMessage(_))
  // merge it with server side pushes
  .merge(updates)
 
You can have an actor in the server handling pushes, and it can look like this
 
val updates =
  Source.actorRef[String](128, OverflowStrategy.fail)
  .mapMaterializedValue{ ref => updaterActor ! Register(ref) }

 
Above will automatically send a Register message to a given actor, passing it an ActorRef to which it can send TextMessage events. If the client cannot keep up with the push frequency it will be kicked out due to OverflowStrategy.fail
 
-Endre
 
 
Cheers
 
Stefan
 
 

 

--
>>>>>>>>>> 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 http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam

 

--
>>>>>>>>>> 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 http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

--
>>>>>>>>>> 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 http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to