Taytay
Taytay

Reputation: 82

Datastax java driver 4.0 configuration programmatically

Is it still possible to configure a Cluster (like Datastax java driver 3.8 driver version) with the new 4.0 version. Or the only solution is to use a configuration file like in the documentation ? https://docs.datastax.com/en/developer/java-driver/4.0/manual/core/configuration/

Upvotes: 1

Views: 1675

Answers (1)

Alex Ott
Alex Ott

Reputation: 87154

Yes, it's possible to configure driver programmatically. Just follow the section "" of driver documentation. You just need to define config loader using DriverConfigLoader.programmaticBuilder, and then use it when building the CqlSession:

DriverConfigLoader loader =
    DriverConfigLoader.programmaticBuilder()
        .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(5))
        .startProfile("slow")
        .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(30))
        .endProfile()
        .build();
CqlSession session = CqlSession.builder().withConfigLoader(loader).build();

Driver has a lot of options available, but as practice shows, it's ok to define many defaults in config file, and use loader only for something non-standard.

P.S. It's better to take driver 4.5 as it works with both OSS & DSE versions... Plus many improvements, like, reactive support, etc.

Upvotes: 2

Related Questions