Hi Endre,

finally I had the time to come back to that issue. Thanks for your advice. 
It works like expected now that I use Merge node.

However, one final question. Why doesn't the whole stream terminate when 
the browser closes the connection? When the outgoing side is closed then 
the whole flow can not work properly any more.

Thanks again,

Stefan


Am Mittwoch, 25. November 2015 17:26:16 UTC+1 schrieb Akka Team:
>
> Hi Stefan,
>
> On Wed, Nov 25, 2015 at 5:17 PM, Stefan Wachter <[email protected] 
> <javascript:>> wrote:
>
>> Hi Endre,
>>  
>> now I watch for the death of the materialized actor for pushing 
>> notification. However, it takes more than 1 minute after the web socket is 
>> closed before a corresponding Terminated messages arrives. Is this an 
>> expected behaviour?
>>
>
> Sorry, I made a small mistake. The simple `merge` above will not work, 
> since it will keep the outgoing side of the WS connection open since the 
> updates source is never closed (merge by default closes once all of its 
> inputs close). You will need to drop down to the Graph DSL and add a Merge 
> node there wiith an eagerClose=true parameter (the current merge on Flow 
> does not have that parameter exposed). This will close the WS as soon as 
> the client closes. 
>
> -Endre
>  
>
>>  
>> Cheers
>>  
>> Stefan
>>   
>> *Gesendet:* Mittwoch, 25. November 2015 um 14:16 Uhr
>> *Von:* "Akka Team" <[email protected] <javascript:>>
>> *An:* "Akka User List" <[email protected] <javascript:>>
>> *Betreff:* Re: Re: [akka-user] How to pipe reactive mongo results into a 
>> WebSocket stream
>> 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.
>>
>> -- 
>> >>>>>>>>>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> 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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to