Java Code Examples for io.vertx.config.ConfigRetriever#create()
The following examples show how to use
io.vertx.config.ConfigRetriever#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VaultConfigStoreTestBase.java From vertx-config with Apache License 2.0 | 7 votes |
/** * Tests the access to secret data encoded as properties with KV-v1 engine. */ @Test public void testAccessToNestedContentAsPropertiesFromSecretV1(TestContext tc) { JsonObject additionalConfig = getRetrieverConfiguration(); JsonObject config = additionalConfig.copy().put("path", "secret/app/foo").put("key", "props"); retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions() .addStore(new ConfigStoreOptions().setType("vault") .setFormat("properties") .setConfig(config))); Async async = tc.async(); retriever.getConfig(json -> { tc.assertTrue(json.succeeded()); JsonObject content = json.result(); tc.assertEquals(content.getString("key"), "val"); tc.assertEquals(content.getInteger("key2"), 5); async.complete(); }); }
Example 2
Source File: ConfigExamples.java From vertx-config with Apache License 2.0 | 6 votes |
public void propsWitHierarchicalStructure() { ConfigStoreOptions propertyWitHierarchical = new ConfigStoreOptions() .setFormat("properties") .setType("file") .setConfig(new JsonObject().put("path", "hierarchical.properties").put("hierarchical", true) ); ConfigRetrieverOptions options = new ConfigRetrieverOptions() .addStore(propertyWitHierarchical); ConfigRetriever configRetriever = ConfigRetriever.create(Vertx.vertx(), options); configRetriever.configStream().handler(config -> { String host = config.getJsonObject("server").getString("host"); Integer port = config.getJsonObject("server").getInteger("port"); JsonArray multiple = config.getJsonObject("multiple").getJsonArray("values"); for (int i = 0; i < multiple.size(); i++) { Integer value = multiple.getInteger(i); } }); }
Example 3
Source File: VaultConfigStoreTestBase.java From vertx-config with Apache License 2.0 | 6 votes |
/** * Tests the access to a specific key of a secret in KV-v1 engine. */ @Test public void testAccessToNestedContentFromSecretV1(TestContext tc) { JsonObject additionalConfig = getRetrieverConfiguration(); JsonObject config = additionalConfig.copy() .put("path", "secret/app/foo").put("key", "nested"); retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions() .addStore(new ConfigStoreOptions().setType("vault") .setConfig(config))); Async async = tc.async(); retriever.getConfig(json -> { if (json.failed()) { json.cause().printStackTrace(); } tc.assertTrue(json.succeeded()); JsonObject content = json.result(); tc.assertEquals(content.getString("foo"), "bar"); async.complete(); }); }
Example 4
Source File: EnvVariablesConfigStoreWithMockEnvTest.java From vertx-config with Apache License 2.0 | 6 votes |
@Test public void testLoadingFromEnvUsingRawData() { retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions() .addStore(new ConfigStoreOptions().setType("env").setConfig(new JsonObject().put("raw-data", true))) ); AtomicBoolean done = new AtomicBoolean(); env.set("name", "12345678901234567890"); retriever.getConfig(ar -> { assertThat(ar.succeeded()).isTrue(); assertThat(ar.result().getString("PATH")).isNotNull(); assertThat(ar.result().getString("name")).isEqualTo("12345678901234567890"); done.set(true); }); await().untilAtomic(done, is(true)); }
Example 5
Source File: DirectoryConfigStoreTest.java From vertx-config with Apache License 2.0 | 6 votes |
@Test public void testWith2FileSetsAndWithIntersection(TestContext context) { Async async = context.async(); retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions() .addStore(new ConfigStoreOptions() .setType("directory") .setConfig(new JsonObject().put("path", "src/test/resources") .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(); }); }
Example 6
Source File: SpringConfigServerStoreTest.java From vertx-config with Apache License 2.0 | 6 votes |
@Test public void testJsonWithFooDev(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.json").put("timeout", 10000)))); retriever.getConfig(json -> { assertThat(json.succeeded()).isTrue(); JsonObject config = json.result(); assertThat(config.getString("bar")).isEqualToIgnoringCase("spam"); assertThat(config.getString("foo")).isEqualToIgnoringCase("from foo development"); assertThat(config.getJsonObject("info").getString("description")).isEqualToIgnoringCase("Spring Cloud Samples"); async.complete(); }); }
Example 7
Source File: SpringConfigServerStoreTest.java From vertx-config with Apache License 2.0 | 6 votes |
@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").put("timeout", 10000)))); retriever.getConfig(json -> { assertThat(json.succeeded()).isTrue(); JsonObject config = json.result(); assertThat(config.getString("bar")).isEqualToIgnoringCase("spam"); assertThat(config.getString("foo")).isEqualToIgnoringCase("from foo development"); assertThat(config.getString("info.description")).isEqualToIgnoringCase("Spring Cloud Samples"); async.complete(); }); }
Example 8
Source File: DirectoryConfigStoreTest.java From vertx-config with Apache License 2.0 | 6 votes |
@Test public void testWithAFileSetMatching2FilesWithConflict(TestContext context) { Async async = context.async(); retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions() .addStore(new ConfigStoreOptions() .setType("directory") .setConfig(new JsonObject().put("path", "src/test/resources") .put("filesets", new JsonArray() .add(new JsonObject().put("pattern", "dir/?.json")) )))); retriever.getConfig(ar -> { assertThat(ar.result().getString("b.name")).isEqualTo("B"); assertThat(ar.result().getString("a.name")).isEqualTo("A"); // Alphabetical order, so B is last. assertThat(ar.result().getString("conflict")).isEqualTo("B"); async.complete(); }); }
Example 9
Source File: SpringConfigServerStoreTest.java From vertx-config with Apache License 2.0 | 6 votes |
@Test public void testJsonWithErrorConfiguration(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.json") .put("timeout", 10000)))); retriever.getConfig(json -> { assertThat(json.succeeded()).isFalse(); async.complete(); }); }
Example 10
Source File: GitConfigStoreTest.java From vertx-config with Apache License 2.0 | 6 votes |
@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(); }); }
Example 11
Source File: RawProcessorTest.java From vertx-config with Apache License 2.0 | 6 votes |
@Test public void testWithJson(TestContext tc) { Async async = tc.async(); retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions() .addStore( new ConfigStoreOptions() .setType("file") .setFormat("raw") .setConfig( new JsonObject() .put("path", "src/test/resources/raw/some-json.json") .put("raw.type", "json-object") .put("raw.key", "some-json"))) ); retriever.getConfig(ar -> { assertThat(ar.result()).isNotNull().isNotEmpty(); assertThat(ar.result().getJsonObject("some-json").encode()).contains("foo", "bar", "num", "1"); async.complete(); }); }
Example 12
Source File: DirectoryConfigStoreTest.java From vertx-config with Apache License 2.0 | 6 votes |
@Test public void testWithAFileSetMatching2FilesWithoutConflict(TestContext context) { Async async = context.async(); retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions() .addStore(new ConfigStoreOptions() .setType("directory") .setConfig(new JsonObject().put("path", "src/test/resources") .put("filesets", new JsonArray() .add(new JsonObject().put("pattern", "dir/a?.json")) )))); retriever.getConfig(ar -> { assertThat(ar.result().getString("b.name")).isNull(); assertThat(ar.result().getString("a.name")).isEqualTo("A"); assertThat(ar.result().getString("c.name")).isEqualTo("C"); assertThat(ar.result().getString("conflict")).isEqualTo("A"); async.complete(); }); }
Example 13
Source File: GitConfigStoreTest.java From vertx-config with Apache License 2.0 | 5 votes |
@Test public void testWithExistingRepoOnTheWrongBranch() throws Exception { git.close(); root = new File("target/junk/work"); git = connect(bareRoot, root); add(git, root, new File("src/test/resources/files/a.json"), "dir"); push(git); branch = "dev"; add(git, root, new File("src/test/resources/files/b.json"), "dir"); push(git); retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions() .setScanPeriod(1000) .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/*.json")) )))); AtomicBoolean done = new AtomicBoolean(); retriever.getConfig(ar -> { assertThat(ar.succeeded()).isTrue(); assertThat(ar.result().getString("a.name")).isEqualTo("A"); done.set(true); }); await().untilAtomic(done, is(true)); updateA(); await().until(() -> "A2".equals(retriever.getCachedConfig().getString("a.name")) && "B".equalsIgnoreCase(retriever.getCachedConfig().getString("b.name"))); }
Example 14
Source File: ConfigYamlExamples.java From vertx-config with Apache License 2.0 | 5 votes |
public void example1(Vertx vertx) { ConfigStoreOptions store = new ConfigStoreOptions() .setType("file") .setFormat("yaml") .setConfig(new JsonObject() .put("path", "my-config.yaml") ); ConfigRetriever retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store)); }
Example 15
Source File: HttpGreetingVerticle.java From vertx-config with Apache License 2.0 | 5 votes |
@Override public void start() { ConfigRetriever retriever = ConfigRetriever.create(vertx); retriever.getConfig(json -> { JsonObject result = json.result(); vertx.createHttpServer() .requestHandler(req -> result.getString("message")) .listen(result.getInteger("port")); }); }
Example 16
Source File: ConfigKubernetesExamples.java From vertx-config with Apache License 2.0 | 5 votes |
public void example1(Vertx vertx) { ConfigStoreOptions store = new ConfigStoreOptions() .setType("configmap") .setConfig(new JsonObject() .put("namespace", "my-project-namespace") .put("name", "configmap-name") ); ConfigRetriever retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store)); }
Example 17
Source File: GitConfigStoreTest.java From vertx-config with Apache License 2.0 | 5 votes |
@Test public void testWithARepositoryWithAMatchingPropertiesFile(TestContext tc) throws GitAPIException, IOException { Async async = tc.async(); 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); add(git, root, new File("src/test/resources/files/regular.properties"), 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", "*.properties") .put("format", "properties")))))); retriever.getConfig(ar -> { if (ar.failed()) { ar.cause().printStackTrace(); } assertThat(ar.succeeded()).isTrue(); assertThat(ar.result()).isNotEmpty(); JsonObject json = ar.result(); assertThat(json).isNotNull(); assertThat(json.getString("key")).isEqualTo("value"); assertThat(json.getBoolean("true")).isTrue(); assertThat(json.getBoolean("false")).isFalse(); assertThat(json.getString("missing")).isNull(); assertThat(json.getInteger("int")).isEqualTo(5); assertThat(json.getDouble("float")).isEqualTo(25.3); async.complete(); }); }
Example 18
Source File: ConfigSupplier.java From quarantyne with Apache License 2.0 | 5 votes |
public ConfigSupplier(Vertx vertx, Supplier<ConfigRetrieverOptions> configRetrieverOptionsSupplier) { ConfigRetrieverOptions configRetrieverOptions = configRetrieverOptionsSupplier.get(); configRetriever = ConfigRetriever.create(vertx, configRetrieverOptions); configRetriever.getConfig( h -> { if (h.succeeded()) { ref.set(read(h.result())); log.info("configuration used is [{}]", ref.get().toString()); /* log.info("configuration will be reloaded every {} ms", configRetrieverOptions.getScanPeriod()); configRetriever.listen( listen -> { if (listen.getNewConfiguration() != null) { Config config = read(listen.getNewConfiguration()); if (config != null) { log.info("new configuration detected [{}], reloading", config.toString()); ref.set(config); } } else { log.error("error while loading configuration, skipping update"); } }); */ } else { log.error("failed to load configuration ", h.cause()); } }); }
Example 19
Source File: YamlProcessorTest.java From vertx-config with Apache License 2.0 | 5 votes |
@Test public void testSimpleYamlConfiguration(TestContext tc) { Async async = tc.async(); retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore( new ConfigStoreOptions() .setType("file") .setFormat("yaml") .setConfig(new JsonObject().put("path", "src/test/resources/simple.yaml")))); retriever.getConfig(ar -> { if (ar.failed()) { ar.cause().printStackTrace(); } assertThat(ar.succeeded()).isTrue(); JsonObject json = ar.result(); assertThat(json.getString("key")).isEqualTo("value"); assertThat(json.getBoolean("true")).isTrue(); assertThat(json.getBoolean("false")).isFalse(); assertThat(json.getString("missing")).isNull(); assertThat(json.getInteger("int")).isEqualTo(5); assertThat(json.getDouble("float")).isEqualTo(25.3); assertThat(json.getJsonArray("array").size()).isEqualTo(3); assertThat(json.getJsonArray("array").contains(1)).isTrue(); assertThat(json.getJsonArray("array").contains(2)).isTrue(); assertThat(json.getJsonArray("array").contains(3)).isTrue(); assertThat(json.getJsonObject("sub").getString("foo")).isEqualTo("bar"); async.complete(); }); }
Example 20
Source File: GitConfigStoreTest.java From vertx-config with Apache License 2.0 | 5 votes |
@Test public void testWithARepositoryWithAMatchingFile(TestContext tc) throws GitAPIException, IOException { Async async = tc.async(); 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); 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()).isNotEmpty(); JsonObject json = ar.result(); assertThat(json).isNotNull(); assertThat(json.getString("key")).isEqualTo("value"); assertThat(json.getBoolean("true")).isTrue(); assertThat(json.getBoolean("false")).isFalse(); assertThat(json.getString("missing")).isNull(); assertThat(json.getInteger("int")).isEqualTo(5); assertThat(json.getDouble("float")).isEqualTo(25.3); assertThat(json.getJsonArray("array").size()).isEqualTo(3); assertThat(json.getJsonArray("array").contains(1)).isTrue(); assertThat(json.getJsonArray("array").contains(2)).isTrue(); assertThat(json.getJsonArray("array").contains(3)).isTrue(); assertThat(json.getJsonObject("sub").getString("foo")).isEqualTo("bar"); async.complete(); }); }