Search code examples
springcassandraspring-datadatastax-java-driverspring-data-cassandra

Set heartbeatintervalseconds using spring xml


I am using spring-data-Cassandra v1.3.2 in my project. Is it possible to set heartbeatintervalseconds using spring configuration XML file.

Getting 4 lines of hearbeat DEBUG logs every 30 seconds in my application logs and i am not sure how to avoid them.


Solution

  • Unfortunately, no.

    After reviewing the SD Cassandra CassandraCqlClusterParser class, it is apparent that you can specify both "local" and "remote" connection pooling options, however, neither handler handles all the Cassandra Java driver "pooling options" appropriately (such as heartbeatIntervalSeconds).

    It appears several other options are missing as well: idleTimeoutSeconds, initializationExecutor, poolTimeoutMillis, and protocolVersion.

    Equally unfortunate is it appears the SD Cassandra PoolOptionsFactoryBean does not support these "pooling options" either.

    However, not all is lost.

    While your SD Cassandra application may resolve it's configuration primarily from XML, it does not preclude you from using a combination of Java config and XML.

    For instance, you could use a Spring Java config class to configure your cluster and express your PoolingOptions in Java config...

    @Configuration
    @ImportResource("/class/path/to/cassandra/config.xml")
    class CassandraConfig {
    
      @Bean
      PoolingOptions poolingOptions() {
        PoolingOptions poolingOptions = new PoolingOptions();
    
        poolingOptions.setHeartbeatIntervalSeconds(30);
        poolingOptions.setIdleTimeoutSeconds(300);
        poolingOptions.setMaxConnectionsPerHost(50);
        poolingOptions.set...
    
        return poolingOptions;
      }
    
      @Bean
      CassandraClusterFactoryBean cluster() {
        CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean()
    
        cluster.setContactPoints("..");
        cluster.setPort(1234);
        cluster.setPoolingOptions(poolingOptions());
        cluster.set...
    
        return cluster;
      }
    }
    

    Hope this helps.

    As an FYI, you may want to upgrade to the "current" Spring Data Cassandra version, 1.4.1.RELEASE.