Supported Formats
Overview
Helidon Config provides several extension modules that support other configuration formats (parsers) and sources. This document describes how to include them and use them in your project. In each case you need to add module dependencies to your project and, in some cases, write your application accordingly.
Additional Formats
File Type Handling
With each of the parsers described here, your application can either
- explicitly add a parser of the correct implementation to the
Config.Builder, or - rely on Java service loading and the config system’s matching of file types and media types to parsers.
If your application creates a Config.Builder with parser services disabled
(see disableParserServices then that builder will not find
the Java services for the various parsers and so will be unable to match the
file type or media type of sources with the corresponding parser automatically.
So if you want to use automatic type matching with a given builder, do not
invoke Config.Builder.disableParserServices().
YAML
Maven Coordinates
Add the following dependency in your project:
Config YAML Dependency in pom.xml:
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-yaml</artifactId>
</dependency>
Using the YAML Parser
The YAML parser handles the following media type:
application/x-yaml- YAML format (file type.yaml)
Automatic selection:
HOCON/JSON
The Helidon HOCON config module handles sources in the HOCON and JSON formats.
Maven Coordinates
Add the following dependency in your project:
Config HOCON Dependency in pom.xml:
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-hocon</artifactId>
</dependency>
Using the HOCON/JSON Parser
The parser handles the following media types:
application/hocon- HOCON format (file type.conf)application/json- JSON format (file type.json)
Automatic selection:
The same module and parser supports file type .json and the media type application/json.
HOCON parser specified - no file type on source:
Media type specified:
HOCON parser specified because parser services disabled:
Customized HOCON parser:
You can also specify ConfigResolveOptions using the
HoconConfigParser.builder().resolveOptions method.
Additional Sources
Etcd
The Helidon Etcd config module supports reading configuration from a specified Etcd key.
Maven Coordinates
Add the following dependency to your project:
Config Etcd Dependency in pom.xml:
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-etcd</artifactId>
</dependency>
Using the Etcd Config Source
To read configuration from an Etcd source, your application uses the
EtcdConfigSourceBuilder.
Use Etcd config source:
The config system will use the YAML parser automatically in this
example because the file type of the key is .yaml.
The EtcdConfigSourceBuilder class extends
AbstractConfigSourceBuilder and so supports the usual
settings on config sources.
Monitoring for Source Changes
The Etcd support includes a change watcher strategy designed for an etcd config source.
Use Etcd config source:
Loading Meta-configuration via Etcd
To read meta-configuration from an Etcd source set the following required properties for the source:
typetoetcd, orclasstoio.helidon.config.etcd.EtcdConfigSourceBuilderuri(typeURI) - Etcd endpoint URI.key(typeString) - Etcd key that is associated with the configuration.api(typeEtcdConfigSourceBuilder.EtcdApi, i.e.v2orv3) - Etcd API version.v2is deprecated.
Other optional properties are inherited from AbstractConfigSourceBuilder.
(see javadoc)
Load Config from meta-configuration:
Config config = Config.create(classpath("config-meta-etcd.yaml"));
Meta-config config-meta-etcd.yaml for the etcd source:
git
The Helidon git config module supports reading configuration from a git repository.
Maven Coordinates
Add the following dependency to your project:
Config git Dependency in pom.xml:
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-git</artifactId>
</dependency>
Using the git Config Source
To read configuration from a git source, your application uses the
GitConfigSourceBuilder.
Use git config source:
Note that the config system will use the HOCON parser in this example because the file type is
.conf. Recall that for this to work the HOCON config module must be on
module-path or classpath.
The GitConfigSourceBuilder supports the usual source builder properties
because it extends AbstractConfigSourceBuilder.
Monitoring for Source Changes
Your application can monitor changes to a configuration loaded from a git source
associating the regular built-in polling strategy with the source.
Use of git config source with polling strategy:
You can also implement your own polling strategy by implementing
PollingStrategy. See the mutability
support and polling strategy
discussions.
Loading Meta-configuration via git
The config system can load information about config sources from meta-configuration rather than requiring your application to construct the builder. To read meta-configuration from a git config source set the following properties for the source:
typetogitorclasstoio.helidon.config.git.GitConfigSourceBuilderpath(typeString) - Relative path to the configuration file in repository.uri(typeURI) - URI to the git repository.directory(typePath) - Directory with a cloned repository, by default a temporary directory.branch(typeString) - git branch (default ismaster).
The meta-configuration must set the path and one of uri or directory.
Other optional properties are inherited from AbstractConfigSourceBuilder
(see javadoc)
Load Config from meta-configuration:
Config config = Config.create(classpath("config-meta-git.yaml"));
Meta-config config-meta-git.yaml for the git source: