use of io.helidon.config.Config in project helidon by oracle.
the class Server method main.
/**
* The main program entry point.
*
* @param args the program arguments
*/
public static void main(String[] args) {
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
// load logging configuration
LogConfig.configureRuntime();
// Get gRPC server config from the "grpc" section of application.yaml
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder(config.get("grpc")).build();
GrpcServer grpcServer = GrpcServer.create(serverConfig, createRouting(config));
// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
grpcServer.start().thenAccept(s -> {
System.out.println("gRPC server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("gRPC server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
// add support for standard and gRPC health checks
HealthSupport health = HealthSupport.builder().addLiveness(HealthChecks.healthChecks()).addLiveness(grpcServer.healthChecks()).build();
// start web server with health endpoint
Routing routing = Routing.builder().register(health).build();
WebServer.create(routing, config.get("webserver")).start().thenAccept(s -> {
System.out.println("HTTP server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("HTTP server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
}
use of io.helidon.config.Config in project helidon by oracle.
the class PokemonMain method createRouting.
/**
* Creates new {@link io.helidon.webserver.Routing}.
*
* @param config configuration of this server
* @return routing configured with JSON support, a health check, and a service
*/
private static Routing createRouting(Config config) {
Config dbConfig = config.get("db");
// Client services are added through a service loader - see mongoDB example for explicit services
DbClient dbClient = DbClient.builder(dbConfig).build();
// Some relational databases do not support DML statement as ping so using query which works for all of them
HealthSupport health = HealthSupport.builder().addLiveness(DbClientHealthCheck.create(dbClient, dbConfig.get("health-check"))).build();
// Initialize database schema
InitializeDb.init(dbClient);
return Routing.builder().register(// Health at "/health"
health).register(// Metrics at "/metrics"
MetricsSupport.create()).register("/db", new PokemonService(dbClient)).build();
}
use of io.helidon.config.Config in project helidon by oracle.
the class OciObjectStorageMain method main.
/**
* Main method.
*
* @param args ignored
*/
public static void main(String[] args) {
LogConfig.configureRuntime();
// as I cannot share my configuration of OCI, let's combine the configuration
// from my home directory with the one compiled into the jar
// when running this example, you can either update the application.yaml in resources directory
// or use the same approach
Config config = buildConfig();
Config ociConfig = config.get("oci");
// this requires OCI configuration in the usual place
// ~/.oci/config
OciObjectStorageRx ociObjectStorage = OciObjectStorageRx.create(ociConfig);
// the following parameters are required
String bucketName = ociConfig.get("objectstorage").get("bucket").asString().get();
String namespace = ociConfig.get("objectstorage").get("namespace").asString().get();
// setup ObjectStorage health check
HealthSupport health = HealthSupport.builder().addLiveness(OciObjectStorageHealthCheck.builder().ociObjectStorage(ociObjectStorage).addBucket(bucketName).namespace(namespace).build()).build();
WebServer.builder().config(config.get("server")).routing(Routing.builder().register(health).register("/files", new ObjectStorageService(ociObjectStorage, bucketName))).build().start().await();
}
use of io.helidon.config.Config in project helidon by oracle.
the class Main method startServer.
/**
* Start the server.
* @return the created WebServer instance
*/
public static Single<WebServer> startServer() {
// load logging configuration
LogConfig.configureRuntime();
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
Single<WebServer> server = WebServer.builder(createRouting(config)).config(config.get("server")).addMediaSupport(JsonpSupport.create()).addMediaSupport(JsonbSupport.create()).build().start();
server.thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port() + "/api/movies");
ws.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
return server;
}
use of io.helidon.config.Config in project helidon by oracle.
the class OciAtpMain method main.
/**
* Application main entry point.
*
* @param args command line arguments.
*/
public static void main(String[] args) {
// load logging configuration
LogConfig.configureRuntime();
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
Config ociConfig = config.get("oci");
// this requires OCI configuration in the usual place
// ~/.oci/config
OciAutonomousDbRx autonomousDbRx = OciAutonomousDbRx.create(ociConfig);
// Prepare routing for the server
WebServer server = WebServer.builder().config(config.get("server")).routing(Routing.builder().register("/atp", new AtpService(autonomousDbRx, config))).build();
// Start the server and print some info.
server.start().thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port() + "/");
});
// Server threads are not daemon. NO need to block. Just react.
server.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
}
Aggregations