[2.5.x] [Scala] A question about handling WebSockets with Actors

105 views
Skip to first unread message

Denis Kalinin

unread,
Oct 19, 2016, 12:57:40 PM10/19/16
to Play Framework
The documantation for Play 2.5 says that it's now possible to handle WebSockets with Akka Streams and actors instead of iteratees. So, now we can create an ActorFlow using the following:

ActorFlow.actorRef

However, it's not clear how to send messages to the created actors from the rest of the application. If there was a way to specify actor's name, I would be able to use actorSelection and send the message only to those actors that satisfy the name pattern. 
But it seems that the name is always "flowActor", which is not very useful.

Is there a way to send messages from the other parts of the app or is it something that should be achieved using some other technique ?

Will Sargent

unread,
Oct 19, 2016, 3:47:49 PM10/19/16
to play-fr...@googlegroups.com
Hi Denis,

You can see an example of streams working with actors in a websocket here, with data being sent to the flowActor:


Hope that helps,
Will.


--
Will Sargent
Engineer, Lightbend, Inc.


--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/f02f7b60-3876-4423-9754-e384415cbe21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Denis Kalinin

unread,
Oct 20, 2016, 6:02:01 AM10/20/16
to Play Framework
Awesome, it works! Thanks Will.

One more question, though. If I create an actor in a controller using 

Sink.actorRef[String](actorRef, akka.actor.Status.Success(()))

and the connection is closed, the actor receives the Success message. I suppose, I should then destroy the actor with 

self ! PoisonPill

because the connection is closed, and the actor is no longer needed, right?



On Wednesday, October 19, 2016 at 10:47:49 PM UTC+3, Will Sargent wrote:
Hi Denis,

You can see an example of streams working with actors in a websocket here, with data being sent to the flowActor:


Hope that helps,
Will.


--
Will Sargent
Engineer, Lightbend, Inc.


On Wed, Oct 19, 2016 at 9:57 AM, Denis Kalinin <denn...@gmail.com> wrote:
The documantation for Play 2.5 says that it's now possible to handle WebSockets with Akka Streams and actors instead of iteratees. So, now we can create an ActorFlow using the following:

ActorFlow.actorRef

However, it's not clear how to send messages to the created actors from the rest of the application. If there was a way to specify actor's name, I would be able to use actorSelection and send the message only to those actors that satisfy the name pattern. 
But it seems that the name is always "flowActor", which is not very useful.

Is there a way to send messages from the other parts of the app or is it something that should be achieved using some other technique ?

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.

Will Sargent

unread,
Oct 20, 2016, 2:10:59 PM10/20/16
to play-fr...@googlegroups.com

--
Will Sargent
Engineer, Lightbend, Inc.


To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/7660ef29-5b00-4f00-8dcd-b96d5f8e37d3%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages