Indra Basak
Indra Basak

Reputation: 7394

Spring Boot 2.3.0.M4, Cassandra, and SSL

I have been using ClusterBuilderCustomizer to customize the SSL connection between my Spring Boot application (2.2.5.RELEASE) and the Cassandra database. After migrating to Spring Boot 2.3.0.M4, my code no longer compiles as the ClusterBuilderCustomizer doesn't exist anymore.

As per Spring Boot 2.3.0 release notes, it has been replaced with DriverConfigLoaderBuilderCustomizer and CqlSessionBuilderCustomizer. Does anyone have a working example on how to use any of these customizer classes with SSL?

Upvotes: 1

Views: 1683

Answers (1)

adutra
adutra

Reputation: 4526

You just need to declare two beans having these types:

@Bean
public CqlSessionBuilderCustomizer cqlSessionBuilderCustomizer() {
    return cqlSessionBuilder -> cqlSessionBuilder
            .withNodeStateListener(new MyNodeStateListener())
            .withSchemaChangeListener(new MySchemChangeListener());
}

@Bean
public DriverConfigLoaderBuilderCustomizer driverConfigLoaderBuilderCustomizer() {
    return loaderBuilder -> loaderBuilder
            .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(10));
    }
}

Use CqlSessionBuilderCustomizer to pass runtime objects to the session builder, e.g. node state listeners or schema change listeners.

Use DriverConfigLoaderBuilderCustomizer to programmatically customize the driver configuration. See the driver docs for more information on how to programmatically configure the driver.

Upvotes: 1

Related Questions