Creating a New Akka Application
To create a new Akka application, use your favorite IDE and build tool to create a new empty project. Akka is provided as regular jar files available through Maven central, so you can use it by just adding the following dependency to your project (after taking a look at akka.io to see which is the latest stable version). NOTE: 2.5.0 will be available very soon.
Maven:
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.11</artifactId>
<version>2.5.0-RC1</version>
</dependency>
Gradle:
compile 'com.typesafe.akka:akka-actor_2.11:2.5.0-RC1'
SBT:
"com.typesafe.akka" %% "akka-actor" % "2.5.0-RC1"
With the project in place, create a simple Java class called Application with a main method, and inside of that, create an ActorSystem:
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
public class Application {
public static void main(String[] args) throws Exception {
final ActorSystem system = ActorSystem.create();
System.out.println("Press any key to terminate");
System.in.read();
System.out.println("Shutting down actor system...");
system.terminate();
}
}
ActorSystem starts and maintains thread pools, and will keep running until you explicitly tell it to terminate, so in this sample we block the main thread until a key is pressed, which triggers termination. If we did not do that, the main method would return and the ActorSystem would keep running.
This Refcard introduces Akka by modeling a simple robot named AkkaBot with Akka’s Java APIs. There is a full set of corresponding Scala APIs, but those will not be covered. The AkkaBot will be modeled as an actor, which is either moving or still, and has a direction it is moving in.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}