Loading json/yaml config with ConfigRetriever to configure Vertx instance

342 views
Skip to first unread message

Robert Djurin

unread,
Feb 12, 2021, 5:13:51 AM2/12/21
to vert.x
Hi,

what is appropriate way to load config with ConfigRetriever to configure Vertx instance with vertxOptions, because ConfigRetriever already need Vertx instance
for example configure zipkin client with sender endpoint?

I know it can be done with system or env variables, but it is ok to get config from json/yaml ... file for that.


For example:

Is it ok to create temporary vertx instance to load config and after config load or failure close this temp vertx.:

Code snippet example:

//Method to load config
Future<JsonObject> loadConfig() {
        
        ConfigRetrieverOptions retrieverOptions = new ConfigRetrieverOptions();

        
        addConfigStores(retrieverOptions, "application.yaml");
        addConfigStore(retrieverOptions, "some path");
        addConfigStore(retrieverOptions, "some path 2");
            
        final Vertx configVertx = Vertx.vertx(); //Creating temporary vertx instance
        ConfigRetriever.create(configVertx, retrieverOptions).getConfig()
                .onComplete(ar -> {
                    JsonObject conf = ar.result();
                    promise.complete(conf);
                    configVertx.close(); //close config vertx
                })
                .onFailure(cause -> {
                    promise.fail(cause);
                    configVertx.close(); //close config vertx
                });

        return promise.future();
}


//on config loaded
loadConfig.onSuccess(cong -> {
    ...
    vertxOptions.setTracingOptions(
        new ZipkinTracingOptions()
            .setServiceName(getConfig(config, "zipkin.service-name"))
            .setSenderOptions(new HttpSenderOptions()
                    .setSenderEndpoint(getConfig(config, "zipkin.endpoint"))
            )
    );

    this.vertx = Vertx.vertx(vertxOptions); //create configured vertx instance
})
.onFailure(t -> ...);




Lars Mårelius

unread,
Feb 12, 2021, 5:49:03 AM2/12/21
to ve...@googlegroups.com
Hi Robert!

Yes, you can start and close a Vert.x context and between there pick up a config retriever with settings you use to start a new Vert.x instance with config from your retrieved file/http/kubernetes ConfigMap.

Here is a method we use:

private static ConfigRetriever getFileConfigRetriever(String configInfo) {
String filePath = configInfo.replace(getFileTypeConfigInfoPattern(), EMPTY);
Vertx vertx = Vertx.vertx();
ConfigRetriever retriever;
retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions()
.addStore(new ConfigStoreOptions()
.setType("file")
.setConfig(new JsonObject().put("path", filePath))));
vertx.close();
return retriever;
}

When we are done with our Runner and config code we will publish on GitHub but we have some more work to do, for example to work with containers in AWS.

I can email you the current code base as a ZIP file if you want to have a look. Warning: we have many steps... :-)

/Morre

----
Lars Mårelius <mo...@tentixo.com> direct: +46 70-867 09 01
Tentixo NG AB
Törnbacken 7, 170 67 Solna
> --
> You received this message because you are subscribed to the Google Groups "vert.x" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/e422d041-332b-41cf-b70e-e8df62b13478n%40googlegroups.com.

signature.asc

Robert Djurin

unread,
Feb 12, 2021, 5:57:34 AM2/12/21
to vert.x
Thanks.

Yes sure you can email me zip if yout wan't.

Lars Mårelius

unread,
Feb 14, 2021, 2:45:48 PM2/14/21
to ve...@googlegroups.com
Wilco!

ETA: A week or two.

/Morre

----
Lars Mårelius <mo...@tentixo.com> direct: +46 70-867 09 01
Tentixo NG AB
Törnbacken 7, 170 67 Solna



> To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/410211a5-85e5-4410-8581-6be2e9097b3en%40googlegroups.com.

signature.asc
Reply all
Reply to author
Forward
0 new messages