Mike Stoddart
Mike Stoddart

Reputation: 506

Using vetx-config to load a configuation file asynchronously

I'm writing a simple vertx Verticle, which loads a configuration file within the start method:

public void start(Promise<Void> startPromise) {}

I originally used:

public void start( final Future<Void> startFuture )

But this method is deprecated.

I am using this code:

ConfigStoreOptions store = new ConfigStoreOptions().setType("file").setFormat("yaml")
        .setConfig(new JsonObject().put("path", MICROSERVICE_CONFIG_FILE));

ConfigRetriever retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store));

retriever.getConfig(ar -> {
    if (ar.failed()) {
        // Failed to retrieve the configuration
        logger.error("Error retrieving service configuration");
    } else {
        config = ar.result();
        this.startService(startPromise);
    }
});

Then, within the "startService" method that gets invoked, I am completing startPromise.

Every few seconds I see two new threads are created:

vert.x-internal-blocking
vert.x-worker-thread-N

These don't get created if I don't load the configuration file. Have I misunderstood how to load a configuration file asynchronously using vertx-config?

Upvotes: 0

Views: 155

Answers (1)

Alexey Soshin
Alexey Soshin

Reputation: 17701

From the ConfigurationRetriever documentation:

The Configuration Retriever periodically retrieve the configuration, and if the outcome is different from the current one, your application can be reconfigured. By default, the configuration is reloaded every 5 seconds.

https://vertx.io/docs/vertx-config/java/#_listening_for_configuration_changes

That's what you see.

Upvotes: 1

Related Questions