For this recipe, we will explore how Play Framework allows us to create asynchronous controllers using futures, in conjunction with Akka actors. The ability to create asynchronous controllers provides a way for developers to trigger background jobs and execute long-running operations asynchronously without sacrificing endpoint responsiveness. Adding Akka to the mix brings a new dimension to fault-tolerant, resilient data services, which become valuable tools in a developer's toolchain in the age of maturing and sophisticating web application requirements.
For Java, we need to take the following steps:
Run the
foo_java
application with Hot-Reloading enabled.Modify the application controller in
foo_java/app/controllers/Application.java
by adding the following contents:public static Promise<Result> asyncExample() { ActorRef fileReaderActor = Akka.system().actorOf(Props.create(FileReaderActor.class)); FileReaderProtocol words =...