How to push regularly to the browser from the server using Comet and Akka Actor
I tried the method of regularly pushing the browser from the server with Comet × Akka Actor using Playframework 2.4, so I will summarize it.
In order to place emphasis on periodically performing browser push, I will implement it as simple as possible.
What is Comet
Comet is a WEB application model that keeps requests for long periods of time after sending requests to the server or until server events occur. To put it briefly, it can push information from the server to the client.
You can check more detail on a following link. https://en.wikipedia.org/wiki/Comet_(programming)
What is Akka Actor
Parallel processing can be implemented using Akka Actor.
You can check more detail on a following link. http://doc.akka.io/docs/akka/current/general/actors.html
How to implement
The flow is following.
- ① Implementation of User (It is not necessary to be a User)
- ② Implementation of Actor
- ③ Implementation of Controller
- ④ Implementation of View
Implementation of User (It is not necessary to be a User)
First, I created User class that has counts.
Creating class fot Actor
Next to create a class to pass to the Actor with Comet object.
Implementation of Actor
Implementation of Controller
Implementation of View
With the forever iframe, the content of the iframe will be rewritten each time there is push from the server.
The point is following source code.
Summary
By applying these, it is possible to create a chat or to keep the user waiting until the value of the table changes.
Github is here.