本文整理汇总了Java中io.vertx.config.ConfigRetriever类的典型用法代码示例。如果您正苦于以下问题:Java ConfigRetriever类的具体用法?Java ConfigRetriever怎么用?Java ConfigRetriever使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigRetriever类属于io.vertx.config包,在下文中一共展示了ConfigRetriever类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
ConfigStoreOptions env = new ConfigStoreOptions()
.setType("file")
.setFormat("json")
.setConfig(new JsonObject().put("path", "sampleconfig.json"));
ConfigRetrieverOptions options = new ConfigRetrieverOptions().addStore(env);
ConfigRetriever retriever = ConfigRetriever.create(vertx, options);
retriever.getConfig(ar -> {
JsonObject rc = ar.result();
System.out.println(rc.encodePrettily());
AppConfig a = rc.mapTo(AppConfig.class);
System.out.println(a);
System.out.println(a.port);
vertx.close();
});
}
示例2: start
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Override
public void start(Future<Void> fut) {
ConfigRetriever retriever = ConfigRetriever.create(vertx);
retriever.getConfig(
config -> {
if (config.failed()) {
fut.fail(config.cause());
} else {
vertx
.createHttpServer()
.requestHandler(r ->
r.response().end("<h1>Hello from my first Vert.x application</h1>"))
.listen(config.result().getInteger("HTTP_PORT", 8080), result -> {
if (result.succeeded()) {
fut.complete();
} else {
fut.fail(result.cause());
}
});
}
}
);
}
示例3: retrieveConfig
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
private Future<Void> retrieveConfig() {
Future<Void> future = Future.future();
ConfigRetrieverOptions options = new ConfigRetrieverOptions();
this.addHoconConfigStoreOptions(options);
this.addDeploymentConfigStoreOptions(options);
ConfigRetriever retriever = ConfigRetriever.create(vertx, options);
retriever.getConfig(ar -> {
if (ar.succeeded()) {
this.configuration = ar.result();
LOG.debug("Retrieved configuration: {}", this.configuration.encodePrettily());
future.complete();
} else {
LOG.error("Unable to retrieve configuration", ar.cause());
future.fail(ar.cause());
}
});
return future;
}
示例4: testWithFooDev
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Test
public void testWithFooDev(TestContext tc) {
Async async = tc.async();
retriever = ConfigRetriever.create(vertx,
new ConfigRetrieverOptions().addStore(
new ConfigStoreOptions()
.setType("spring-config-server")
.setConfig(new JsonObject().put("url", "http://localhost:8888/foo/development"))));
retriever.getConfig(json -> {
assertThat(json.succeeded()).isTrue();
JsonObject config = json.result();
assertThat(config.getString("bar")).isEqualToIgnoringCase("spam");
assertThat(config.getString("foo")).isEqualToIgnoringCase("baz");
assertThat(config.getString("info.description")).isEqualToIgnoringCase("Spring Cloud Samples");
async.complete();
});
}
示例5: testWithUnknownConfiguration
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Test
public void testWithUnknownConfiguration(TestContext tc) {
Async async = tc.async();
retriever = ConfigRetriever.create(vertx,
new ConfigRetrieverOptions().addStore(
new ConfigStoreOptions()
.setType("spring-config-server")
.setConfig(new JsonObject()
.put("url", "http://localhost:8888/missing/missing")
.put("timeout", 10000))));
retriever.getConfig(json -> {
assertThat(json.succeeded()).isTrue();
JsonObject config = json.result();
assertThat(config.getString("eureka.client.serviceUrl.defaultZone"))
.isEqualToIgnoringCase("http://localhost:8761/eureka/");
async.complete();
});
}
示例6: testWithErrorConfiguration
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Test
public void testWithErrorConfiguration(TestContext tc) {
Async async = tc.async();
retriever = ConfigRetriever.create(vertx,
new ConfigRetrieverOptions().addStore(
new ConfigStoreOptions()
.setType("spring-config-server")
.setConfig(new JsonObject()
.put("url", "http://localhost:8888/missing/missing/missing")
.put("timeout", 10000))));
retriever.getConfig(json -> {
assertThat(json.succeeded()).isFalse();
async.complete();
});
}
示例7: testWithWrongServerConfiguration
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Test
public void testWithWrongServerConfiguration(TestContext tc) {
Async async = tc.async();
retriever = ConfigRetriever.create(vertx,
new ConfigRetrieverOptions().addStore(
new ConfigStoreOptions()
.setType("spring-config-server")
.setConfig(new JsonObject()
.put("url", "http://not-valid.de")
.put("timeout", 10000))));
retriever.getConfig(json -> {
assertThat(json.succeeded()).isFalse();
async.complete();
});
}
示例8: testOnMasterWithASingleFile
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Test
public void testOnMasterWithASingleFile(TestContext tc) throws GitAPIException, IOException {
Async async = tc.async();
retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(new
ConfigStoreOptions().setType("git").setConfig(new JsonObject()
.put("url", REPO)
.put("path", "target/junk/work")
.put("filesets", new JsonArray().add(new JsonObject().put("pattern", "a.json"))))));
retriever.getConfig(ar -> {
assertThat(ar.succeeded()).isTrue();
assertThat(ar.result()).isNotEmpty();
JsonObject json = ar.result();
assertThat(json).isNotNull();
assertThat(json.getString("branch")).isEqualToIgnoringCase("master");
assertThat(json.getString("name")).isEqualToIgnoringCase("A");
async.complete();
});
}
示例9: testOnDevWithATwoFiles
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Test
public void testOnDevWithATwoFiles(TestContext tc) throws GitAPIException, IOException {
Async async = tc.async();
retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(new
ConfigStoreOptions().setType("git").setConfig(new JsonObject()
.put("url", REPO)
.put("path", "target/junk/work")
.put("branch", "dev")
.put("filesets", new JsonArray().add(new JsonObject().put("pattern", "*.json"))))));
retriever.getConfig(ar -> {
assertThat(ar.succeeded()).isTrue();
assertThat(ar.result()).isNotEmpty();
JsonObject json = ar.result();
assertThat(json).isNotNull();
assertThat(json.getString("branch")).isEqualToIgnoringCase("dev");
assertThat(json.getString("key")).isEqualToIgnoringCase("value");
assertThat(json.getString("keyB")).isEqualToIgnoringCase("valueB");
assertThat(json.getString("name")).isEqualToIgnoringCase("B");
async.complete();
});
}
示例10: testWithEmptyRepository
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Test
public void testWithEmptyRepository(TestContext tc) throws GitAPIException, IOException {
Async async = tc.async();
add(git, root, new File("src/test/resources/files/some-text.txt"), null);
push(git);
retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(new
ConfigStoreOptions().setType("git").setConfig(new JsonObject()
.put("url", bareRoot.getAbsolutePath())
.put("path", "target/junk/work")
.put("filesets", new JsonArray().add(new JsonObject().put("pattern", "**/*.json"))))));
retriever.getConfig(ar -> {
assertThat(ar.succeeded()).isTrue();
assertThat(ar.result()).isEmpty();
async.complete();
});
}
示例11: testWithACustomBranch
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Test
public void testWithACustomBranch(TestContext tc) throws GitAPIException, IOException {
Async async = tc.async();
add(git, root, new File("src/test/resources/files/a.json"), null);
branch = "dev";
add(git, root, new File("src/test/resources/files/regular.json"), null);
push(git);
retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(new
ConfigStoreOptions().setType("git").setConfig(new JsonObject()
.put("url", bareRoot.getAbsolutePath())
.put("path", "target/junk/work")
.put("branch", branch)
.put("filesets", new JsonArray().add(new JsonObject().put("pattern", "*.json"))))));
retriever.getConfig(ar -> {
assertThat(ar.succeeded()).isTrue();
assertThat(ar.result()).isNotEmpty();
JsonObject json = ar.result();
assertThat(json).isNotNull();
assertThat(json.getString("key")).isEqualTo("value");
async.complete();
});
}
示例12: testWithNonExistingPath
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Test
public void testWithNonExistingPath(TestContext tc) throws IOException, GitAPIException {
add(git, root, new File("src/test/resources/files/some-text.txt"), null);
add(git, root, new File("src/test/resources/files/regular.json"), null);
push(git);
Async async = tc.async();
retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(new
ConfigStoreOptions().setType("git").setConfig(new JsonObject()
.put("url", bareRoot.getAbsolutePath())
.put("path", "target/junk/do-not-exist")
.put("filesets", new JsonArray().add(new JsonObject().put("pattern", "*.json"))))));
retriever.getConfig(ar -> {
assertThat(ar.succeeded()).isTrue();
assertThat(ar.result()).isNotEmpty();
async.complete();
});
}
示例13: testWith2FileSetsAndNoIntersection
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Test
public void testWith2FileSetsAndNoIntersection(TestContext tc) throws GitAPIException, IOException {
Async async = tc.async();
add(git, root, new File("src/test/resources/files/regular.json"), "file");
add(git, root, new File("src/test/resources/files/a.json"), "dir");
push(git);
retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(new
ConfigStoreOptions().setType("git").setConfig(new JsonObject()
.put("url", bareRoot.getAbsolutePath())
.put("path", "target/junk/work")
.put("filesets", new JsonArray()
.add(new JsonObject().put("pattern", "file/reg*.json"))
.add(new JsonObject().put("pattern", "dir/a.*son"))
))));
retriever.getConfig(ar -> {
assertThat(ar.result().getString("key")).isEqualTo("value");
assertThat(ar.result().getString("a.name")).isEqualTo("A");
async.complete();
});
}
示例14: testWith2FileSetsAndWithIntersection
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Test
public void testWith2FileSetsAndWithIntersection(TestContext tc) throws GitAPIException, IOException {
Async async = tc.async();
add(git, root, new File("src/test/resources/files/b.json"), "dir");
add(git, root, new File("src/test/resources/files/a.json"), "dir");
push(git);
retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(new
ConfigStoreOptions().setType("git").setConfig(new JsonObject()
.put("url", bareRoot.getAbsolutePath())
.put("path", "target/junk/work")
.put("filesets", new JsonArray()
.add(new JsonObject().put("pattern", "dir/b.json"))
.add(new JsonObject().put("pattern", "dir/a.*son"))
))));
retriever.getConfig(ar -> {
assertThat(ar.result().getString("a.name")).isEqualTo("A");
assertThat(ar.result().getString("b.name")).isEqualTo("B");
assertThat(ar.result().getString("conflict")).isEqualTo("A");
async.complete();
});
}
示例15: testWith2FileSetsAndWithIntersectionReversed
import io.vertx.config.ConfigRetriever; //导入依赖的package包/类
@Test
public void testWith2FileSetsAndWithIntersectionReversed(TestContext tc) throws GitAPIException, IOException {
Async async = tc.async();
add(git, root, new File("src/test/resources/files/b.json"), "dir");
add(git, root, new File("src/test/resources/files/a.json"), "dir");
push(git);
retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(new
ConfigStoreOptions().setType("git").setConfig(new JsonObject()
.put("url", bareRoot.getAbsolutePath())
.put("path", "target/junk/work")
.put("filesets", new JsonArray()
.add(new JsonObject().put("pattern", "dir/a.*son"))
.add(new JsonObject().put("pattern", "dir/b.json"))
))));
retriever.getConfig(ar -> {
assertThat(ar.result().getString("conflict")).isEqualTo("B");
assertThat(ar.result().getString("a.name")).isEqualTo("A");
assertThat(ar.result().getString("b.name")).isEqualTo("B");
async.complete();
});
}