本文整理汇总了Java中akka.http.javadsl.Http.bindAndHandle方法的典型用法代码示例。如果您正苦于以下问题:Java Http.bindAndHandle方法的具体用法?Java Http.bindAndHandle怎么用?Java Http.bindAndHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类akka.http.javadsl.Http
的用法示例。
在下文中一共展示了Http.bindAndHandle方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import akka.http.javadsl.Http; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ActorSystem system = ActorSystem.create("ServiceB");
final Http http = Http.get(system);
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Main app = new Main();
final ActorRef serviceBackendActor = system.actorOf(BackendActor.props(), "backendActor");
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.createRoute(serviceBackendActor).flow(system, materializer);
final CompletionStage<ServerBinding> binding =
http.bindAndHandle(
routeFlow,
ConnectHttp.toHost("localhost", 8081),
materializer);
System.out.println("Server online at http://localhost:8081/\nPress RETURN to stop...");
System.in.read(); // let it run until user presses return
binding
.thenCompose(ServerBinding::unbind) // trigger unbinding from the port
.thenAccept(unbound -> system.terminate()); // and shutdown when done
}
示例2: main
import akka.http.javadsl.Http; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
final ActorSystem system = ActorSystem.create("ServiceA");
final Http http = Http.get(system);
final ActorMaterializer materializer = ActorMaterializer.create(system);
final StreamMain app = new StreamMain();
final ActorRef streamActor = system.actorOf(StreamActor.props());
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.createRoute(streamActor).flow(system, materializer);
final CompletionStage<ServerBinding> binding =
http.bindAndHandle(
routeFlow,
ConnectHttp.toHost("localhost", 8080),
materializer);
System.out.println("Server online at http://localhost:8080/\nPress RETURN to stop...");
System.in.read(); // let it run until user presses return
System.in.read(); // let it run until user presses return
binding
.thenCompose(ServerBinding::unbind) // trigger unbinding from the port
.thenAccept(unbound -> system.terminate()); // and shutdown when done
}
示例3: main
import akka.http.javadsl.Http; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
final ActorSystem system = ActorSystem.create();
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Route route = InfillionRoutes.routes();
final Flow<HttpRequest, HttpResponse, NotUsed> flow = route.flow(system, materializer);
final Http http = Http.get(system);
final CompletionStage<ServerBinding> bindings = http.bindAndHandle(flow, ConnectHttp.toHost("127.0.0.1", 8080), materializer);
System.out.println("Type RETURN to exit");
System.in.read();
bindings
.thenCompose(ServerBinding::unbind)
.thenAccept(unbound -> system.terminate());
}
示例4: main
import akka.http.javadsl.Http; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
final ActorSystem system = ActorSystem.create("example");
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Http http = Http.get(system);
final MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
final SetSessionJava app = new SetSessionJava(dispatcher);
final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);
System.out.println("Server started, press enter to stop");
System.in.read();
binding
.thenCompose(ServerBinding::unbind)
.thenAccept(unbound -> system.terminate());
}
示例5: main
import akka.http.javadsl.Http; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
final ActorSystem system = ActorSystem.create("example");
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Http http = Http.get(system);
final MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
final VariousSessionsJava app = new VariousSessionsJava(dispatcher);
final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);
System.out.println("Server started, press enter to stop");
System.in.read();
binding
.thenCompose(ServerBinding::unbind)
.thenAccept(unbound -> system.terminate());
}
示例6: main
import akka.http.javadsl.Http; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
// ** akka-http boiler plate **
ActorSystem system = ActorSystem.create("example");
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Http http = Http.get(system);
// ** akka-http-session setup **
MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
final SessionInvalidationJava app = new SessionInvalidationJava(dispatcher);
// ** akka-http boiler plate continued **
final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);
System.out.println("Server started, press enter to stop");
System.in.read();
binding
.thenCompose(ServerBinding::unbind)
.thenAccept(unbound -> system.terminate());
}
示例7: main
import akka.http.javadsl.Http; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
// ** akka-http boiler plate **
ActorSystem system = ActorSystem.create("example");
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Http http = Http.get(system);
// ** akka-http-session setup **
MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
final JavaJwtExample app = new JavaJwtExample(dispatcher);
// ** akka-http boiler plate continued **
final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);
System.out.println("Server started, press enter to stop");
System.in.read();
binding
.thenCompose(ServerBinding::unbind)
.thenAccept(unbound -> system.terminate());
}
示例8: main
import akka.http.javadsl.Http; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
// ** akka-http boiler plate **
ActorSystem system = ActorSystem.create("example");
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Http http = Http.get(system);
// ** akka-http-session setup **
MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
final JavaExample app = new JavaExample(dispatcher);
// ** akka-http boiler plate continued **
final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);
System.out.println("Server started, press enter to stop");
System.in.read();
binding
.thenCompose(ServerBinding::unbind)
.thenAccept(unbound -> system.terminate());
}
示例9: main
import akka.http.javadsl.Http; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ActorSystem system = ActorSystem.create("ServiceA");
final Http http = Http.get(system);
final ActorMaterializer materializer = ActorMaterializer.create(system);
final ActorMain app = new ActorMain();
ActorRef serviceBackendActor = null;
switch (Integer.parseInt(args[0])) {
case 0:
serviceBackendActor = system.actorOf(Step0BackendActor.props(), "step0");
break;
case 1:
serviceBackendActor = system.actorOf(Step1BackendActor.props(), "step1");
break;
case 2:
serviceBackendActor = system.actorOf(Step2BackendActor.props(), "step2");
break;
case 3:
serviceBackendActor = system.actorOf(Step3BackendActor.props(), "step3");
break;
default:
throw new RuntimeException("Unknown example.");
}
//final ActorRef serviceBackendActor = system.actorOf(BackendActor.props(), "backendActor");
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.createRoute(serviceBackendActor).flow(system, materializer);
final CompletionStage<ServerBinding> binding =
http.bindAndHandle(
routeFlow,
ConnectHttp.toHost("localhost", 8080),
materializer);
System.out.println("Server online at http://localhost:8080/\nPress RETURN to stop...");
System.in.read(); // let it run until user presses return
System.in.read(); // let it run until user presses return
binding
.thenCompose(ServerBinding::unbind) // trigger unbinding from the port
.thenAccept(unbound -> system.terminate()); // and shutdown when done
}