akka Hello world Akka Hello World (Java 8)


Add this dependency to your project POM:


Create an Actor

public class HelloWorldActor extends AbstractActor {

    public HelloActor() {
            .match(SayHello.class, this::sayHello)
            .match(SayBye.class, this::sayBye)

    private void sayHello(final SayHello message) {
        System.out.println("Hello World");

    private void sayHello(final SayBye message) {
        System.out.println("Bye World");

    public static Props props() {
        return Props.create(HelloWorldActor.class);

Create a Junit test for the actor

public class HelloActorTest {

    private ActorSystem actorSystem;

    public void setUp() throws Exception {
        actorSystem = ActorSystem.create();

    public void tearDown() throws Exception {

    public void testSayHello() throws Exception {
        new JavaTestKit(actorSystem) {
                ActorRef helloActorRef = actorSystem.actorOf(HelloWorldActor.props());
                helloActorRef.tell(new SayHello(), ActorRef.noSender());
                helloActorRef.tell(new SayBye(), ActorRef.noSender());