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/
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.
Related
I am migrating from Datastax Cassandra Driver 1.9 to 4.14.x
I would be interested how to migrate this code:
Builder builder =
Cluster.builder()
.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM));
Is that the right approach and the equivalent to the code above?
DriverConfigLoader driverConfigLoader = DriverConfigLoader.programmaticBuilder()
.withString(DefaultDriverOption.REQUEST_CONSISTENCY, "LOCAL_QUORUM")
.build();
final CqlSessionBuilder cqlSessionBuilder =
CqlSession.builder()
.withConfigLoader(driverConfigLoader);
Thanks in advance!
With the drivers 4.x keys configuration keys be defined in application.conf. As long as the file is in the classpath it will load properties and it is the best way to setup your application without having to change your code. documentation
Knowing this, if you still want to do configuration programmatically you indeed have the correct approach:
DriverConfigLoader loader = DriverConfigLoader.programmaticBuilder()
.withStringList(DefaultDriverOption.CONTACT_POINTS, Arrays.asList("127.0.0.1:9042"))
.withString(DefaultDriverOption.REQUEST_CONSISTENCY, "LOCAL_QUORUM")
.withString(DefaultDriverOption.LOAD_BALANCING_LOCAL_DATACENTER, "datacenter1")
.withString(DefaultDriverOption.SESSION_KEYSPACE, KEYSPACE_NAME)
.withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(5))
// If you want to override with an execution profile
.startProfile("slow")
.withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(30))
.endProfile()
.build();
// Use it to create the session
try (CqlSession cqlSession = CqlSession.builder().withConfigLoader(loader).build()) {
// Use session
LOGGER.info("[OK] Connected to Keyspace {}", cqlSession.getKeyspace().get());
}
A lot of 4.x code can be found here and used as reference.
The Cassandra Java driver was completely refactored from the ground up in version 4.0 so it does mean that it is not binary-compatible with earlier versions so the previous APIs and classes like QueryOptions have been replaced.
There are several ways to configure the driver including the programmaticBuilder() in your example which allows you to programmatically specify configuration options.
There is also a configuration API which allows you to use dynamic profiles or load configuration options at runtime.
Your example code is a direct translation of the programmatic builder in previous releases and it will work. However, our opinion is that in most cases, developers should configure the driver using an application configuration properties file (application.conf or its variations) placed in the application classpath. With this option, the driver configuration is de-coupled from your application.
The obvious advantage of this method is that you can easily reconfigure the driver without having to recompile your application.
There is a reference configuration file (reference.conf) available that has tons of in-line comments for developers. For details, see Configuring the Cassandra Java driver. Cheers!
I have a springboot application where I am trying to add following to application.properties file
spring.datasource.initialize=false
When I add this I see a warning as below:
I tried finding out what's the new property that replaces this deprecated property but in vain.
Can anybody help on this!
Having a reference to a migration guide would be great.
In Spring Boot 2.5, 'spring.datasource.initialization-mode' has been depracated as well:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.5-Release-Notes#SQL-Script-DataSource-Initialization
you should use:
spring.sql.init.mode=always
or
spring.sql.init.mode=never
You can read more at:
https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.data-initialization
As per the document
Spring Boot automatically creates the schema of an embedded
DataSource. This behaviour can be customized by using the
spring.datasource.initialization-mode property. For instance, if you
want to always initialize the DataSource regardless of its type:
spring.datasource.initialization-mode=always
Look at this migration guide
As per Spring Boot Migration mentioned in Github
Basic DataSource initialization is now only enabled for embedded data
sources and will switch off as soon as you’re using a production
database. The new spring.datasource.initialization-mode (replacing
spring.datasource.initialize) offers more control.
spring.datasource.initialization-mode=always
The property spring.datasource.initialization-mode from Spring boot verion 2.7 and onwards is not any more depracated. It has been completely removed!
So the change into the replacement property spring.sql.init.mode is a must do from now on.
Spring Boot 2.7 changelog
You can use spring.jpa.defer-datasource-initialization. Refer to this Spring Documentation on how to Initialize a Database Using Basic SQL Scripts:
spring.jpa.defer-datasource-initialization=true
spring.sql.init.enabled=true - to initialize database by data.sql script located in application resources
spring.sql.init.enabled=false - to
According to some research about Lagom and Cassandra, I found that:
Lagom uses DataStax Java Driver for Cassandra, and
DataStax Java Driver only supports Cassandra 3.0.x (link)
So, if I want to use Cassandra 3.11 and Lagom, what should I do:
Should I configure Lagom with another Cassandra driver like Achilles, PlayORM, ... (link). Is that possible?
is DataStax support Cassandra 3.11 in the enterprise edition?
Any help, please?
DataStax Java Driver 3.2.0 that is used by Lagom should work with Cassandra 3.11 out of the box (just checked it myself using simple queries).
Even if it won't work out of the box, you can explicitly override driver version in Maven or other build system.
I have configured cassandra cluster with 2 datacenters, and 3 nodes each. i wanted to use DCAwareRoundRobinPolicy to specify the local datacenter. i tried using both Datastax java driver 2.0.2 and 3.1. but with 2.0.2 there no compile time error rather in run-time i am getting NoSuchMethodError and 3.1 giving me the DCAwareRoundRobinPolicy() constructor is not visible.
Can anyone please let me know how to fix this issue?
Thanks in advance.
For the Java Cassandra Driver 3.1 you now use a builder to create your DCAwareRoundRobinPolicy
DCAwareRoundRobinPolicy dcAwareRoundRobinPolicy = DCAwareRoundRobinPolicy.builder()
.withLocalDc("my-dc")
.withUsedHostsPerRemoteDc(1)
.build();
I would also suggest using TokenAware as well so when you are building your cluster add
Cluster.Builder()
.withLoadBalancingPolicy(new TokenAwarePolicy(dcAwareRoundRobinPolicy))
I am trying to integrate a web tool we have with a sql server database using Integrated Security. I have been looking around trying to find a unix version of the sqljdbc4.jar however I cannot seem to find one with .so files only .dll's.
Does anyone know where I can get a version with the .so files required or another way to use integrated security?
Currently my application is failing to connect with
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication
and I can see
WARNING: Failed to load the sqljdbc_auth.dll
earlier in the logs.
Using version 2.5 of mssqljdbc.
According to these docs, beginning with MSSQL JDBC Driver 4.0, you should be able to specify authenticationScheme=JavaKerberos to use the pure Java Kerberos implementation that doesn't need sqljdbc_auth.dll.
Note, I haven't tried this.
I know its late but for anyone searching this, try the following:
put the sqljdbc_auth.dll in your resource folder then add the following code
ClassLoader classLoader = TestDBConnection.class.getClassLoader();
File file = new File(classLoader.getResource("sqljdbc_auth.dll").getFile());
System.setProperty("java.library.path", file.getParent());