Initial Commit

This commit is contained in:
Kotharu 2018-10-21 18:40:44 +05:30
parent 8696022889
commit 632e46c2a0
3 changed files with 17 additions and 10 deletions

View File

@ -23,17 +23,19 @@ public class AkkaHttpServer extends AllDirectives {
}
public static void main(String[] args) throws Exception {
ActorSystem system = ActorSystem.create("helloAkkaHttpServer");
final ActorMaterializer materializer = ActorMaterializer.create(system);
ActorSystem system = ActorSystem.create("helloAkkaHttpServer");
final ActorMaterializer materializer = ActorMaterializer.create(system);
ActorRef userActorRef = system.actorOf(UserActor.props(), "userActor");
ActorRef userActorRef = system.actorOf(UserActor.props(), "userActor");
AkkaHttpServer app = new AkkaHttpServer(system, userActorRef);
AkkaHttpServer app = new AkkaHttpServer(system, userActorRef);
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.userRoutes.routes().flow(system, materializer);
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.userRoutes.routes()
.flow(system, materializer);
final CompletionStage<ServerBinding> binding = Http.get(system).bindAndHandle(routeFlow,
ConnectHttp.toHost("localhost", 8080), materializer);
final CompletionStage<ServerBinding> binding = Http.get(system)
.bindAndHandle(routeFlow, ConnectHttp.toHost("localhost", 8080), materializer);
System.out.println("Server is online at http://localhost:8080/");
}
System.out.println("Server is online at http://localhost:8080/");
}
}

View File

@ -1,5 +1,7 @@
package com.baeldung.akkahttp;
import java.io.Serializable;
/**
* Defines all messages related to User Actor
*

View File

@ -1,10 +1,12 @@
package com.baeldung.akkahttp;
import java.time.Duration;
import java.util.Optional;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;
import com.baeldung.akkahttp.UserRegistryMessages.ActionPerformed;
import com.baeldung.akkahttp.UserRegistryMessages.CreateUser;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.event.Logging;
@ -16,6 +18,7 @@ import akka.http.javadsl.server.PathMatchers;
import akka.http.javadsl.server.Route;
import akka.pattern.PatternsCS;
import akka.util.Timeout;
import scala.concurrent.duration.Duration;
public class UserRoutes extends AllDirectives {