servicetalk-examples/http/service-composition/src/main/java/io/servicetalk/examples/http/service/composition/GatewayServer.java
/**
     * Starts this server.
     *
     * @param args Program arguments, none supported yet.
     * @throws Exception If the server could not be started.
     */
Starts this server.
@param args Program arguments, none supported yet.
@throws Exception If the server could not be started.
Starts this server . @param args Program arguments none supported yet . @throws Exception If the server could not be started .
public static void main(String[] args) throws Exception {
        try (CompositeCloseable resources = newCompositeCloseable()) {
            IoExecutor ioExecutor = resources.prepend(createIoExecutor());
            StreamingHttpClient recommendationsClient =
                    newClient(ioExecutor, RECOMMENDATIONS_BACKEND_ADDRESS, resources, "recommendations backend");
            HttpClient metadataClient =
                    newClient(ioExecutor, METADATA_BACKEND_ADDRESS, resources, "metadata backend").asClient();
            HttpClient userClient =
                    newClient(ioExecutor, USER_BACKEND_ADDRESS, resources, "user backend").asClient();
            HttpClient ratingsClient =
                    newClient(ioExecutor, RATINGS_BACKEND_ADDRESS, resources, "ratings backend").asClient();
            HttpPredicateRouterBuilder routerBuilder = new HttpPredicateRouterBuilder();
            final StreamingHttpService gatewayService =
                    routerBuilder.whenPathStartsWith("/recommendations/stream")
                            .thenRouteTo(new StreamingGatewayService(recommendationsClient, metadataClient,
                                    ratingsClient, userClient))
                            .whenPathStartsWith("/recommendations/aggregated")
                            .thenRouteTo(new GatewayService(recommendationsClient.asClient(),
                                    metadataClient, ratingsClient, userClient))
                            .whenPathStartsWith("/recommendations/blocking")
                            .thenRouteTo(new BlockingGatewayService(recommendationsClient.asBlockingClient(),
                                    metadataClient.asBlockingClient(),
                                    ratingsClient.asBlockingClient(),
                                    userClient.asBlockingClient()))
                            .buildStreaming();
            ServerContext serverContext = HttpServers.forPort(8080)
                    .ioExecutor(ioExecutor)
                    .appendServiceFilter(new BadResponseHandlingServiceFilter())
                    .listenStreamingAndAwait(gatewayService);
            LOGGER.info("Listening on {}", serverContext.listenAddress());
            serverContext.awaitShutdown();
        }
    }
public static void main ( String [ ] args ) throws Exception { try ( CompositeCloseable resources = newCompositeCloseable ( ) ) { IoExecutor ioExecutor = resources . prepend ( createIoExecutor ( ) ) ; StreamingHttpClient recommendationsClient = newClient ( ioExecutor , RECOMMENDATIONS_BACKEND_ADDRESS , resources , "recommendations backend" ) ; HttpClient metadataClient = newClient ( ioExecutor , METADATA_BACKEND_ADDRESS , resources , "metadata backend" ) . asClient ( ) ; HttpClient userClient = newClient ( ioExecutor , USER_BACKEND_ADDRESS , resources , "user backend" ) . asClient ( ) ; HttpClient ratingsClient = newClient ( ioExecutor , RATINGS_BACKEND_ADDRESS , resources , "ratings backend" ) . asClient ( ) ; HttpPredicateRouterBuilder routerBuilder = new HttpPredicateRouterBuilder ( ) ; final StreamingHttpService gatewayService = routerBuilder . whenPathStartsWith ( "/recommendations/stream" ) . thenRouteTo ( new StreamingGatewayService ( recommendationsClient , metadataClient , ratingsClient , userClient ) ) . whenPathStartsWith ( "/recommendations/aggregated" ) . thenRouteTo ( new GatewayService ( recommendationsClient . asClient ( ) , metadataClient , ratingsClient , userClient ) ) . whenPathStartsWith ( "/recommendations/blocking" ) . thenRouteTo ( new BlockingGatewayService ( recommendationsClient . asBlockingClient ( ) , metadataClient . asBlockingClient ( ) , ratingsClient . asBlockingClient ( ) , userClient . asBlockingClient ( ) ) ) . buildStreaming ( ) ; ServerContext serverContext = HttpServers . forPort ( 8080 ) . ioExecutor ( ioExecutor ) . appendServiceFilter ( new BadResponseHandlingServiceFilter ( ) ) . listenStreamingAndAwait ( gatewayService ) ; LOGGER . info ( "Listening on {}" , serverContext . listenAddress ( ) ) ; serverContext . awaitShutdown ( ) ; } }
Starts this server.
Starts this server .
// Create an AutoCloseable representing all resources used in this example. // Shared IoExecutor for the application. // Create clients for the different backends we are going to use in the gateway. // Gateway supports different endpoints for blocking, streaming or aggregated implementations. // We create a router to express these endpoints. // Create configurable starter for HTTP server. // Starting the server will start listening for incoming client requests. // Blocks and awaits shutdown of the server this ServerContext represents.