/** * This method is called when the verticle is deployed. */ @Override public void start(Future<Void> future) { discovery = ServiceDiscovery.create(vertx); ConfigRetriever retriever = ConfigRetriever.create(vertx, getConfigurationOptions()); retriever.rxGetConfig() // Read the configuration, and deploy a MarketDataVerticle for each company listed in the configuration. .flatMap(config -> Observable.fromIterable(config.getJsonArray("companies")) .cast(JsonObject.class) // Deploy the verticle with a configuration. .flatMapSingle(company -> vertx.rxDeployVerticle(MarketDataVerticle.class.getName(), new DeploymentOptions().setConfig(company))) .toList() ) // Deploy another verticle .flatMap(l -> vertx.rxDeployVerticle(RestQuoteAPIVerticle.class.getName())) // Expose the market-data message source .flatMap(x -> discovery.rxPublish(MessageSource.createRecord("market-data", ADDRESS))) .subscribe((rec, err) -> { if (rec != null) { this.record = rec; future.complete(); } else { future.fail(err); } }); }
private Single<JsonObject> loadConfig(JsonObject config) { if(config != null) { AppGlobals.get().setConfig(config); return Single.just(config); } String path = "conf/config.json"; return vertx.fileSystem().rxExists(path) .flatMap(exists -> { if(exists) { ConfigStoreOptions fileStore = new ConfigStoreOptions() .setType("file") .setConfig(new JsonObject().put("path", path)); ConfigRetrieverOptions configRetrieverOptions = new ConfigRetrieverOptions() .addStore(fileStore); ConfigRetriever retriever = ConfigRetriever.create(vertx, configRetrieverOptions); return retriever.rxGetConfig().map(loadedConfig -> { AppGlobals.get().setConfig(loadedConfig); return loadedConfig; }); } else { // empty config JsonObject emptyConfig = new JsonObject(); AppGlobals.get().setConfig(emptyConfig); return Single.just(emptyConfig); } }); }
protected Single<JsonObject> loadConfig(JsonObject config) { if(config != null) { AppGlobals.get().setConfig(config); return Single.just(config); } String path = "conf/config.json"; return vertx.fileSystem().rxExists(path) .flatMap(exists -> { if(exists) { ConfigStoreOptions fileStore = new ConfigStoreOptions() .setType("file") .setConfig(new JsonObject().put("path", path)); ConfigRetrieverOptions configRetrieverOptions = new ConfigRetrieverOptions() .addStore(fileStore); ConfigRetriever retriever = ConfigRetriever.create(vertx, configRetrieverOptions); return retriever.rxGetConfig().map(loadedConfig -> { AppGlobals.get().setConfig(loadedConfig); return loadedConfig; }); } else { // empty config JsonObject emptyConfig = new JsonObject(); AppGlobals.get().setConfig(emptyConfig); return Single.just(emptyConfig); } }); }
retriever.rxGetConfig() .doOnSuccess(config -> jdbc = JDBCClient.createShared(vertx, config, "My-Reading-List"))