/** * 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 ); }
/** * 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 ); }
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(); } }
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 }
.get(theSystem) .bindAndHandle(routes().flow(theSystem, materializer), ConnectHttp.toHost(host, port),
.get(theSystem) .bindAndHandle(routes().flow(theSystem, materializer), ConnectHttp.toHost(host, port),
.get(theSystem) .bindAndHandle(routes().flow(theSystem, materializer), ConnectHttp.toHost(host, port),
/** * 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; }); } }
/** * 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; }); } }
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; }); }
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; }); }
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)),
final CompletionStage<ServerBinding> binding = Http.get(actorSystem) .bindAndHandle(createRoute(actorSystem, config, proxyActor, streamingActor, healthCheckActor) .flow(actorSystem, materializer),
bindingCompletionStage = Http.get(context().system()) .bindAndHandle( route.flow(context().system(), materializer),
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(),
final CompletionStage<ServerBinding> binding = Http.get(getContext().system()) .bindAndHandle(createRoute(getContext().system(), healthCheckingActor).flow(getContext().system(), materializer), ConnectHttp.toHost(hostname, httpConfig.getPort()), materializer);