0
votes

I have a scenario where I have a bunch of Akka Actors running with each Actor representing an IoT device. I have a web application based on Play inside which these Actors are running and are connected to these IoT devices.

Now I want to expose the signals from there Actors to the outside world by means of a WebSocket Endpoint. Each of the Actor has some sort of mechanism with which I can ask for the latest signal status.

My idea is to do the following:

  1. Add a WebSocket endpoint in my controller which expects the id of the IoT device for which it needs the signals. In this controller, I will do an actor selection to get the Actor instance that corresponds to the id of the IoT device that is passed in.

  2. Use the ActorRef obtained in step 1 and instantiate the WebSocketActor

  3. In this WebSocketActor, I will instantiate a Monix Observable that will at regular intervals use the actorRef and ask it for the signals.

  4. As soon as I get these signals, I will pass it on to the WebSocket endpoint

Now my question is:

  1. What happens say if a client has opened a WebSocket stream and after some time the Actor representing the IoT device is dead. I probably should handle this situation in my WebSocketActor. But how would this look like?

  2. If the Actor representing the IoT device comes back alive (assuming that I have some supervison set up), can I continue processing the client that opened the socket connection before the Actor was dead? I mean will the client need to somehow close and open the connection again?

Please suggestions?

1

1 Answers

1
votes

If you'd like to see an Akka actors + Monix integration example, communicating over WebSocket, look no further than the monix-sample project.

The code handles network failure. If you'll load that sample in the browser, disconnect the network and you'll see it recover once connectivity is back on.