io.vertx.config.ConfigStoreOptions Java Examples

The following examples show how to use io.vertx.config.ConfigStoreOptions. 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: YamlProcessorTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyYaml(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/empty.yaml"))));

  retriever.getConfig(ar -> {
    expectSuccess(ar);
    assertThat(ar.result()).isNotNull();
    assertThat(ar.result()).isEmpty();
    async.complete();
  });
}
 
Example #2
Source File: VaultConfigStoreTestBase.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the access to a secret with KV-v2 engine.
 */
@Test
public void testAccessToSecretV2(TestContext tc) {
  JsonObject additionalConfig = getRetrieverConfiguration();
  JsonObject config = additionalConfig.copy().put("path", "secret-v2/data/app/foo");

  retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions()
    .addStore(new ConfigStoreOptions().setType("vault").setConfig(config)));

  Async async = tc.async();

  retriever.getConfig(json -> {
    tc.assertTrue(json.succeeded());
    JsonObject content = json.result();
    tc.assertEquals("hello", content.getString("message"));
    tc.assertEquals(10, content.getInteger("counter"));

    async.complete();
  });
}
 
Example #3
Source File: DirectoryConfigStoreTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: SpringConfigServerStoreTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testJsonWithUnknownConfiguration(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.json")
          .put("timeout", 10000))));


  retriever.getConfig(json -> {
    assertThat(json.succeeded()).isTrue();
    JsonObject config = json.result();
    assertThat(config.getJsonObject("eureka").getJsonObject("client").getJsonObject("serviceUrl").getString("defaultZone"))
      .isEqualToIgnoringCase("http://localhost:8761/eureka/");
    async.complete();
  });
}
 
Example #5
Source File: VaultConfigStoreTestBase.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
/**
 * Tests accessing a missing key from an existing secret.
 */
@Test
public void testRetrievingAMissingKey(TestContext tc) {
  JsonObject additionalConfig = getRetrieverConfiguration();
  JsonObject config = additionalConfig.copy()
    .put("path", "secret/app/foo").put("key", "missing");

  retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions()
    .addStore(new ConfigStoreOptions().setType("vault")
      .setConfig(config)));

  Async async = tc.async();

  retriever.getConfig(json -> {
    tc.assertTrue(json.succeeded());
    tc.assertTrue(json.result().isEmpty());
    async.complete();
  });
}
 
Example #6
Source File: GitConfigStoreWithGithubTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@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();
  });
}
 
Example #7
Source File: GitConfigStoreTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@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();
  });

}
 
Example #8
Source File: GitConfigStoreTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@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();
  });

}
 
Example #9
Source File: GitConfigStoreTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@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();
  });
}
 
Example #10
Source File: SystemPropertiesConfigStoreWithRawDataTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadingFromSysWithoutRawData() {
  retriever = ConfigRetriever.create(vertx,
    new ConfigRetrieverOptions()
      .addStore(new ConfigStoreOptions().setType("sys"))
  );

  AtomicBoolean done = new AtomicBoolean();

  System.setProperty("name", "12345678901234567891");


  retriever.getConfig(ar -> {
    assertThat(ar.succeeded()).isTrue();
    // Converted value, totally wrong ;-)
    assertThat(ar.result().getInteger("name")).isEqualTo(2147483647);
    done.set(true);
  });
  await().untilAtomic(done, is(true));
}
 
Example #11
Source File: GitConfigStoreTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@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();
  });

}
 
Example #12
Source File: GitConfigStoreTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithDeepConfigMerge(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 -> {
    // Both level-3 objects must exist.
    assertThat(ar.result().getJsonObject("parent").getJsonObject("level_2").getString("key1")).isEqualTo("A");
    assertThat(ar.result().getJsonObject("parent").getJsonObject("level_2").getString("key2")).isEqualTo("B");
    async.complete();
  });

}
 
Example #13
Source File: DirectoryConfigStoreTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithAFileSetMatching2FilesOneNotBeingAJsonFile(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.failed());
    assertThat(ar.cause()).isInstanceOf(DecodeException.class);
    async.complete();
  });
}
 
Example #14
Source File: RawProcessorTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithUnrecognizedType(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/logo-white-big.png")
                          .put("raw.key", "any")
                          .put("raw.type", "not a valid type")))
  );

  retriever.getConfig(ar -> {
    assertThat(ar.failed());
    assertThat(ar.cause().getMessage()).contains("raw.type");
    async.complete();
  });
}
 
Example #15
Source File: VaultConfigStoreTestBase.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #16
Source File: VaultConfigStoreTestBase.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the access to a secret with KV-v1 engine.
 */
@Test
public void testAccessToSecretV1(TestContext tc) {
  JsonObject additionalConfig = getRetrieverConfiguration();
  JsonObject config = additionalConfig.copy().put("path", "secret/app/foo");

  retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions()
    .addStore(new ConfigStoreOptions().setType("vault").setConfig(config)));

  Async async = tc.async();

  retriever.getConfig(json -> {
    tc.assertTrue(json.succeeded());
    JsonObject content = json.result();
    tc.assertEquals("hello", content.getString("message"));
    tc.assertEquals(10, content.getInteger("counter"));

    async.complete();
  });
}
 
Example #17
Source File: YamlProcessorTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithTextFile(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/some-text.txt"))));

  retriever.getConfig(ar -> {
    assertThat(ar.failed()).isTrue();
    assertThat(ar.cause()).isNotNull().isInstanceOf(DecodeException.class);
    async.complete();
  });
}
 
Example #18
Source File: YamlProcessorTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithMissingFile(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/some-missing-file.yaml"))));

  retriever.getConfig(ar -> {
    assertThat(ar.failed()).isTrue();
    assertThat(ar.cause()).isNotNull().isInstanceOf(FileSystemException.class);
    async.complete();
  });
}
 
Example #19
Source File: YamlProcessorTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicYamlFile(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/basic.yaml"))));

  retriever.getConfig(ar -> {
    expectSuccess(ar);
    JsonObject json = ar.result();
    assertThat(json.getInteger("invoice")).isEqualTo(34843);
    assertThat(json.getString("date")).isEqualTo("2001-01-23");
    JsonObject bill = json.getJsonObject("bill-to");
    assertThat(bill).contains(entry("given", "Chris"), entry("family", "Dumars"));
    assertThat(bill.getJsonObject("address")).isNotNull().isNotEmpty();
    JsonArray products = json.getJsonArray("product");
    assertThat(products).hasSize(2);
    assertThat(products.getJsonObject(0).getFloat("price")).isEqualTo(450.0f);
    assertThat(products.getJsonObject(1).getDouble("price")).isEqualTo(2392.0);
    assertThat(json.getString("comments")).contains("Late afternoon is best. Backup contact is Nancy Billsmer @");
    async.complete();
  });
}
 
Example #20
Source File: HoconProcessorTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyHocon(TestContext tc) {
  Async async = tc.async();
  retriever = ConfigRetriever.create(vertx,
      new ConfigRetrieverOptions().addStore(
          new ConfigStoreOptions()
              .setType("file")
              .setFormat("hocon")
              .setConfig(new JsonObject().put("path", "src/test/resources/empty.conf"))));

  retriever.getConfig(ar -> {
    assertThat(ar.result()).isNotNull();
    assertThat(ar.result()).isEmpty();
    async.complete();
  });
}
 
Example #21
Source File: VaultConfigStoreTestBase.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
/**
 * Tests accessing a missing secret.
 */
@Test
public void testRetrievingAMissingSecret(TestContext tc) {
  JsonObject additionalConfig = getRetrieverConfiguration();
  JsonObject config = additionalConfig.copy()
    .put("path", "secret/app/missing");

  retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions()
    .addStore(new ConfigStoreOptions().setType("vault")
      .setConfig(config)));

  Async async = tc.async();

  retriever.getConfig(json -> {
    tc.assertTrue(json.succeeded());
    JsonObject content = json.result();
    tc.assertTrue(content.isEmpty());
    async.complete();
  });
}
 
Example #22
Source File: HoconProcessorTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithMissingFile(TestContext tc) {
  Async async = tc.async();
  retriever = ConfigRetriever.create(vertx,
      new ConfigRetrieverOptions().addStore(
          new ConfigStoreOptions()
              .setType("file")
              .setFormat("hocon")
              .setConfig(new JsonObject().put("path", "src/test/resources/some-missing-file.conf"))));

  retriever.getConfig(ar -> {
    assertThat(ar.failed()).isTrue();
    assertThat(ar.cause()).isNotNull().isInstanceOf(FileSystemException.class);
    async.complete();
  });
}
 
Example #23
Source File: VaultConfigStoreTestBase.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
/**
 * Tests accessing a specific key from a missing secret.
 */
@Test
public void testRetrievingAKeyFromAMissingSecret(TestContext tc) {
  JsonObject additionalConfig = getRetrieverConfiguration();
  JsonObject config = additionalConfig.copy()
    .put("path", "secret/app/missing").put("key", "missing");

  retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions()
    .addStore(new ConfigStoreOptions().setType("vault")
      .setConfig(config)));

  Async async = tc.async();

  retriever.getConfig(json -> {
    tc.assertTrue(json.succeeded());
    tc.assertTrue(json.result().isEmpty());
    async.complete();
  });
}
 
Example #24
Source File: HoconProcessorTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimplePropertiesConfiguration(TestContext tc) {
  Async async = tc.async();
  retriever = ConfigRetriever.create(vertx,
      new ConfigRetrieverOptions().addStore(
          new ConfigStoreOptions()
              .setType("file")
              .setFormat("hocon")
              .setConfig(new JsonObject().put("path", "src/test/resources/regular.properties"))));

  retriever.getConfig(ar -> {
    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);

    async.complete();
  });
}
 
Example #25
Source File: ConfigExamples.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
public void example2(Vertx vertx) {
  ConfigStoreOptions httpStore = new ConfigStoreOptions()
    .setType("http")
    .setConfig(new JsonObject()
      .put("host", "localhost").put("port", 8080).put("path", "/conf"));

  ConfigStoreOptions fileStore = new ConfigStoreOptions()
    .setType("file")
    .setConfig(new JsonObject().put("path", "my-config.json"));

  ConfigStoreOptions sysPropsStore = new ConfigStoreOptions().setType("sys");


  ConfigRetrieverOptions options = new ConfigRetrieverOptions()
    .addStore(httpStore).addStore(fileStore).addStore(sysPropsStore);

  ConfigRetriever retriever = ConfigRetriever.create(vertx, options);
}
 
Example #26
Source File: DirectoryConfigStoreTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testWith2FileSetsAndNoIntersection(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", "file/reg*.json"))
                  .add(new JsonObject().put("pattern", "dir/a.*son"))
              ))));
  retriever.getConfig(ar -> {
    ConfigChecker.check(ar);
    assertThat(ar.result().getString("a.name")).isEqualTo("A");
    async.complete();
  });
}
 
Example #27
Source File: VaultConfigStoreTestBase.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the access to secret data encoded as properties with KV-v2 engine.
 */
@Test
public void testAccessToNestedContentAsPropertiesFromSecretV2(TestContext tc) {
  JsonObject additionalConfig = getRetrieverConfiguration();
  JsonObject config = additionalConfig.copy().put("path", "secret-v2/data/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 #28
Source File: ConfigExamples.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
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 #29
Source File: ConfigExamples.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
public void stream(ConfigStoreOptions store1, ConfigStoreOptions store2) {
  ConfigRetrieverOptions options = new ConfigRetrieverOptions()
    .setScanPeriod(2000)
    .addStore(store1)
    .addStore(store2);

  ConfigRetriever retriever = ConfigRetriever.create(Vertx.vertx(), options);
  retriever.configStream()
    .endHandler(v -> {
      // retriever closed
    })
    .exceptionHandler(t -> {
      // an error has been caught while retrieving the configuration
    })
    .handler(conf -> {
      // the configuration
    });

}
 
Example #30
Source File: VerticleDeployment.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
public void configureVertx() {
  // Create a first instance of Vert.x
  Vertx vertx = Vertx.vertx();
  // Create the config retriever
  ConfigRetriever retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions()
    .addStore(new ConfigStoreOptions().setType("file").setConfig(new JsonObject().put("path", "vertx.json"))));

  // Retrieve the configuration
  retriever.getConfig(json -> {
    JsonObject result = json.result();
    // Close the vert.x instance, we don't need it anymore.
    vertx.close();

    // Create a new Vert.x instance using the retrieve configuration
    VertxOptions options = new VertxOptions(result);
    Vertx newVertx = Vertx.vertx(options);

    // Deploy your verticle
    newVertx.deployVerticle(GreetingVerticle.class.getName(), new DeploymentOptions().setConfig(result.getJsonObject("a")));
  });
}