Environment Configuration Example (end to end)

1,075 views
Skip to first unread message

mic...@frobl.com

unread,
May 9, 2017, 2:56:48 AM5/9/17
to vert.x

I am really excited to learn vert.x, however, coming from a whole different world (Golang, NodeJS), I do not see *exactly how* to make vert.x read configuration from the environment.


http://vertx.io/blog/vert-x-application-configuration should provide an example that instead of reading from a configuration json file, it instead gets the variable from the environment. Our company never uses configuration files, and always configures from environment. 


I know that it *should* be obvious, and maybe it's the whiskey, maybe it's the lack of sleep, but I don't understand how to make the server listen on port 8082 reading from the environment's PORT value.


Thank you in advance!





mic...@frobl.com

unread,
May 9, 2017, 3:10:30 AM5/9/17
to vert.x

  ConfigStoreOptions store = new ConfigStoreOptions();

  store.setType("env");

  ConfigRetrieverOptions options = new ConfigRetrieverOptions()

  .addStore(store);


  ConfigRetriever retriever = ConfigRetriever.create(vertx, options);

  

// There is no example code for what to *do* with retriever.
 

    vertx.createHttpServer()

        .requestHandler(router::accept)

        .listen(

               

                config().getInteger("PORT", 9999),





Tim Fox

unread,
May 9, 2017, 3:55:14 AM5/9/17
to vert.x
System.getEnv("PORT") ?

Clement Escoffier

unread,
May 9, 2017, 4:40:39 AM5/9/17
to ve...@googlegroups.com
Hello,

There are several approaches.

1) The simplest being: System.getEnv(“PORT”) as Tim said.
2) If you need more complex scenario, where the configuration can comes from different locations and you need to handle “overrides” (for instance system properties overrides env variables), check http://vertx.io/docs/vertx-config/java/.

Clement

 


-- 
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.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/83859b14-3334-4805-a3f7-8b4db8901e7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages