Hi Stefan,
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? > Inside the stream, it is simply signaled as the end of stream. From the actor where you send updates to the WS socket, you can just simply watch the ActorRef you got in the Register message. > 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.) > I think there is a default idle-timeout applied to all Http connections for safety. Currently it is not possible to lift it for certain connections (for example WS connections). The workaround is to use keepAlive and use some small heartbeat message to send to the browser. If the idle timeout is large enough, then you don't need to send keepAlive messages very frequently so it is not a large overhead. Also this allows your browser client to detect lost connections early by detecting missed heartbeats, so it is not a bad pattern in the end. -Endre > > 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. > -- 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.
