Search in sources :

Example 1 with Routes

use of com.example.akka.routes.Routes in project swagger-akka-http-sample-java by pjfanning.

the class Main method main.

public static void main(String[] args) throws Exception {
    // boot up server using the route as defined below
    ActorSystem system = ActorSystem.create("routes");
    final Http http = Http.get(system);
    // In order to access all directives we need an instance where the routes
    // are defined.
    Main app = new Main();
    final Route routes = app.concat(new Routes().createRoute(), new SwaggerDocService().createRoute());
    final CompletionStage<ServerBinding> binding = http.newServerAt("localhost", 12345).bind(routes);
    System.out.println("Server online at http://localhost:12345/\nPress RETURN to stop...");
    // let it run until user presses return
    System.in.read();
    // trigger unbinding from the port
    binding.thenCompose(ServerBinding::unbind).thenAccept(// and shutdown when done
    unbound -> system.terminate());
}
Also used : ActorSystem(akka.actor.ActorSystem) Http(akka.http.javadsl.Http) Routes(com.example.akka.routes.Routes) ServerBinding(akka.http.javadsl.ServerBinding) Route(akka.http.javadsl.server.Route)

Aggregations

ActorSystem (akka.actor.ActorSystem)1 Http (akka.http.javadsl.Http)1 ServerBinding (akka.http.javadsl.ServerBinding)1 Route (akka.http.javadsl.server.Route)1 Routes (com.example.akka.routes.Routes)1