本文整理了Java中akka.http.javadsl.Http.get()
方法的一些代码示例,展示了Http.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Http.get()
方法的具体详情如下:
包路径:akka.http.javadsl.Http
类名称:Http
方法名:get
暂无
代码示例来源:origin: org.eclipse.ditto/ditto-services-gateway-util
/**
* Creates a CompletionStage for the passed {@link HttpRequest} containing the {@link HttpResponse}.
*
* @return the HttpResponse CompletionStage.
*/
public CompletionStage<HttpResponse> createSingleHttpRequest(final HttpRequest request) {
return Http.get(actorSystem).singleRequest(
request,
Http.get(actorSystem).defaultClientHttpsContext(),
connectionPoolSettings,
actorSystem.log(),
actorMaterializer
);
}
代码示例来源:origin: eclipse/ditto
/**
* Creates a CompletionStage for the passed {@link HttpRequest} containing the {@link HttpResponse}.
*
* @return the HttpResponse CompletionStage.
*/
public CompletionStage<HttpResponse> createSingleHttpRequest(final HttpRequest request) {
return Http.get(actorSystem).singleRequest(
request,
Http.get(actorSystem).defaultClientHttpsContext(),
connectionPoolSettings,
actorSystem.log(),
actorMaterializer
);
}
代码示例来源:origin: wxyyxc1992/Backend-Boilerplates
public static void main(String[] args) throws Exception {
ActorSystem system = ActorSystem.create();
try {
final Materializer materializer = ActorMaterializer.create(system);
final Function<HttpRequest, HttpResponse> handler = request -> handleRequest(request);
CompletionStage<ServerBinding> serverBindingFuture =
Http.get(system).bindAndHandleSync(
handler, ConnectHttp.toHost("localhost", 8080), materializer);
// will throw if binding fails
serverBindingFuture.toCompletableFuture().get(1, TimeUnit.SECONDS);
System.out.println("Press ENTER to stop.");
new BufferedReader(new InputStreamReader(System.in)).readLine();
} finally {
system.terminate();
}
}
代码示例来源:origin: zhihuili/flower
public void startHttpServer() throws Exception {
final Http http = Http.get(system);
final ActorMaterializer materializer = ActorMaterializer.create(system);
ActorRef userRegistryActor = system.actorOf(ServiceRegistryActor.props(), "serviceRegistryActor");
ServiceRoutes serviceRoutes = new ServiceRoutes(system, userRegistryActor);
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = serviceRoutes.routes().flow(system, materializer);
final CompletionStage<ServerBinding> binding = http.bindAndHandle(routeFlow,
ConnectHttp.toHost("localhost", 8096), materializer);
System.out.println("Server online at http://localhost:8096/");
System.in.read(); // let it run until user presses return
}
代码示例来源:origin: com.typesafe.akka/akka-http_2.11
.get(theSystem)
.bindAndHandle(routes().flow(theSystem, materializer),
ConnectHttp.toHost(host, port),
代码示例来源:origin: com.typesafe.akka/akka-http
.get(theSystem)
.bindAndHandle(routes().flow(theSystem, materializer),
ConnectHttp.toHost(host, port),
代码示例来源:origin: com.typesafe.akka/akka-http_2.12
.get(theSystem)
.bindAndHandle(routes().flow(theSystem, materializer),
ConnectHttp.toHost(host, port),
代码示例来源:origin: org.eclipse.ditto/ditto-services-base
/**
* Starts Prometheus HTTP endpoint on which Prometheus may scrape the data.
*/
private void startKamonPrometheusHttpEndpoint(final ActorSystem actorSystem) {
if (configReader.metrics().isPrometheusEnabled() && prometheusReporter != null) {
final ActorMaterializer materializer = createActorMaterializer(actorSystem);
final Route prometheusReporterRoute = PrometheusReporterRoute
.buildPrometheusReporterRoute(prometheusReporter);
final CompletionStage<ServerBinding> binding = Http.get(actorSystem)
.bindAndHandle(prometheusReporterRoute.flow(actorSystem, materializer),
ConnectHttp.toHost(configReader.metrics().getPrometheusHostname(),
configReader.metrics().getPrometheusPort()), materializer);
binding.thenAccept(theBinding -> CoordinatedShutdown.get(actorSystem).addTask(
CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_prometheus_http_endpoint", () -> {
logger.info("Gracefully shutting down Prometheus HTTP endpoint..");
// prometheus requests don't get the luxury of being processed a long time after shutdown:
return theBinding.terminate(Duration.ofSeconds(1))
.handle((httpTerminated, e) -> Done.getInstance());
})
).exceptionally(failure -> {
logger.error("Kamon Prometheus HTTP endpoint could not be started: {}", failure.getMessage(), failure);
logger.error("Terminating actorSystem!");
actorSystem.terminate();
return null;
});
}
}
代码示例来源:origin: eclipse/ditto
/**
* Starts Prometheus HTTP endpoint on which Prometheus may scrape the data.
*/
private void startKamonPrometheusHttpEndpoint(final ActorSystem actorSystem) {
if (configReader.metrics().isPrometheusEnabled() && prometheusReporter != null) {
final ActorMaterializer materializer = createActorMaterializer(actorSystem);
final Route prometheusReporterRoute = PrometheusReporterRoute
.buildPrometheusReporterRoute(prometheusReporter);
final CompletionStage<ServerBinding> binding = Http.get(actorSystem)
.bindAndHandle(prometheusReporterRoute.flow(actorSystem, materializer),
ConnectHttp.toHost(configReader.metrics().getPrometheusHostname(),
configReader.metrics().getPrometheusPort()), materializer);
binding.thenAccept(theBinding -> CoordinatedShutdown.get(actorSystem).addTask(
CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_prometheus_http_endpoint", () -> {
logger.info("Gracefully shutting down Prometheus HTTP endpoint..");
// prometheus requests don't get the luxury of being processed a long time after shutdown:
return theBinding.terminate(Duration.ofSeconds(1))
.handle((httpTerminated, e) -> Done.getInstance());
})
).exceptionally(failure -> {
logger.error("Kamon Prometheus HTTP endpoint could not be started: {}", failure.getMessage(), failure);
logger.error("Terminating actorSystem!");
actorSystem.terminate();
return null;
});
}
}
代码示例来源:origin: eclipse/ditto
private void bindHttpStatusRoute(final ActorRef healthCheckingActor, final HttpConfigReader httpConfig,
final ActorMaterializer materializer) {
String hostname = httpConfig.getHostname();
if (hostname.isEmpty()) {
hostname = ConfigUtil.getLocalHostAddress();
log.info("No explicit hostname configured, using HTTP hostname: {}", hostname);
}
final CompletionStage<ServerBinding> binding = Http.get(getContext().system())
.bindAndHandle(createRoute(getContext().system(), healthCheckingActor).flow(getContext().system(),
materializer), ConnectHttp.toHost(hostname, httpConfig.getPort()), materializer);
binding.thenAccept(theBinding -> CoordinatedShutdown.get(getContext().getSystem()).addTask(
CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_health_http_endpoint", () -> {
log.info("Gracefully shutting down status/health HTTP endpoint..");
return theBinding.terminate(Duration.ofSeconds(1))
.handle((httpTerminated, e) -> Done.getInstance());
})
).exceptionally(failure -> {
log.error(failure, "Something very bad happened: {}", failure.getMessage());
getContext().system().terminate();
return null;
});
}
代码示例来源:origin: eclipse/ditto
private void createHealthCheckingActorHttpBinding(final HttpConfigReader httpConfig,
final ActorRef healthCheckingActor, final ActorMaterializer materializer) {
String hostname = httpConfig.getHostname();
if (hostname.isEmpty()) {
hostname = ConfigUtil.getLocalHostAddress();
log.info("No explicit hostname configured, using HTTP hostname: {}", hostname);
}
final CompletionStage<ServerBinding> binding = Http.get(getContext().system()) //
.bindAndHandle(
createRoute(getContext().system(), healthCheckingActor).flow(getContext().system(),
materializer),
ConnectHttp.toHost(hostname, httpConfig.getPort()), materializer);
binding.thenAccept(theBinding -> CoordinatedShutdown.get(getContext().getSystem()).addTask(
CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_health_http_endpoint", () -> {
log.info("Gracefully shutting down status/health HTTP endpoint..");
return theBinding.terminate(Duration.ofSeconds(1))
.handle((httpTerminated, e) -> Done.getInstance());
})
).exceptionally(failure -> {
log.error(failure, "Something very bad happened: {}", failure.getMessage());
getContext().system().terminate();
return null;
});
}
代码示例来源:origin: eclipse/ditto
final CompletionStage<ServerBinding> binding = Http.get(getContext().system()).bindAndHandle( //
createRoute(getContext().system(), healthCheckingActor).flow(getContext().system(), materializer),
ConnectHttp.toHost(hostname, config.getInt(ConfigKeys.Http.PORT)),
代码示例来源:origin: eclipse/ditto
final CompletionStage<ServerBinding> binding = Http.get(actorSystem)
.bindAndHandle(createRoute(actorSystem, config, proxyActor, streamingActor, healthCheckActor)
.flow(actorSystem, materializer),
代码示例来源:origin: johanandren/akka-actor-java8-webinar
bindingCompletionStage = Http.get(context().system())
.bindAndHandle(
route.flow(context().system(), materializer),
代码示例来源:origin: eclipse/ditto
log.info("No explicit hostname configured, using HTTP hostname <{}>.", hostname);
final CompletionStage<ServerBinding> binding = Http.get(getContext().system())
.bindAndHandle(
createRoute(getContext().system(), healthCheckingActor).flow(getContext().system(),
代码示例来源:origin: eclipse/ditto
final CompletionStage<ServerBinding> binding = Http.get(getContext().system())
.bindAndHandle(createRoute(getContext().system(), healthCheckingActor).flow(getContext().system(),
materializer), ConnectHttp.toHost(hostname, httpConfig.getPort()), materializer);
内容来源于网络,如有侵权,请联系作者删除!