DSE driver configuration
The DSE driver uses the same configuration mechanism as the OSS driver.
It bundles its own dse-reference.conf file for configuration defaults, that inherits from the OSS
driver’s reference.conf
. This allows us not to repeat everything in the DSE configuration file, it
only contains DSE-specific options.
For example, the OSS driver’s reference.conf
defines a default request consistency level:
# reference.conf in com.datastax.oss::java-driver-core
datastax-java-driver {
basic.request.consistency = LOCAL_ONE
}
The DSE driver’s dse-reference.conf
does not override that option, so it inherits LOCAL_ONE
. On
the other hand, it defines its own defaults for DSE-specific features, for example the traversal
source for graph statements:
# dse-reference.conf in com.datastax.dse::dse-java-driver-core
datastax-java-driver {
basic.graph.traversal-source = g
}
So if you execute a graph statement with the DSE driver, you get a default consistency of
LOCAL_ONE
and the default traversal source g
. If you put an application.conf
in your
application classpath, you can override either of those defaults:
# application.conf in your application
datastax-java-driver {
basic {
request.consistency = ONE
graph.traversal-source = a
}
}
Alternate application config locations
Like the OSS driver, the DSE driver includes other config loader implementations:
-
DseDriverConfigLoader.fromClasspath: still load from the classpath, but use a different resource
name. For example “config” will try to load
config.conf
,config.json
orconfig.properties
. - DseDriverConfigLoader.fromFile: load from a file on the local filesystem.
- DseDriverConfigLoader.fromUrl: load from a URL.
- DseDriverConfigLoader.programmaticBuilder: provide config options programmatically.
File file = new File("/path/to/application.conf");
DseSession session = DseSession.builder()
.withConfigLoader(DseDriverConfigLoader.fromFile(file))
.build();
Make sure you use the factory methods from DseDriverConfigLoader
. If you use the methods from
DriverConfigLoader
(the OSS class), the resulting loader won’t read dse-reference.conf
, and the
driver might fail to initialize because some DSE-specific options are missing.
Advanced topics
If you are providing your own DriverConfigLoader
implementation (for example to change the config
prefix or load from a different source), here’s how you can inherit the driver’s built-in
defaults:
DriverConfigLoader myConfigLoader =
new DefaultDriverConfigLoader(
() -> {
// Load from your custom source / prefix
Config myConfig = ...;
// Load dse-reference.conf from the DSE driver artifact
Config dseConfig =
ConfigFactory.parseResourcesAnySyntax("dse-reference")
.getConfig("datastax-java-driver");
// Load reference.conf from the OSS driver artifact
Config ossConfig =
ConfigFactory.parseResourcesAnySyntax("reference")
.getConfig("datastax-java-driver");
return myConfig.withFallback(dseConfig).withFallback(ossConfig);
});
DseSession session = DseSession.builder().withConfigLoader(myConfigLoader).build();