Neither Spring Boot nor Spring Data Cassandra provides a HealthIndicator for Cassandra out of the box, but building your own is straightforward. You just need to create a new HealthIndicator bean that interacts with Cassandra. For example:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health.Builder;
import org.springframework.dao.DataAccessException;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.stereotype.Component;
@Component
public class CassandraHealthIndicator extends AbstractHealthIndicator {
private final CassandraOperations cassandra;
@Autowired
public CassandraHealthIndicator(CassandraOperations cassandra) {
this.cassandra = cassandra;
}
@Override
protected void doHealthCheck(Builder builder) throws Exception {
try {
this.cassandra.execute("SELECT now() FROM system.local");
builder.up().build();
} catch (DataAccessException ex) {
builder.down(ex).build();
}
}
}
As long as this bean exists in your application context Spring Boot's Actuator component will find it and use it when determining your application's health.
Exactly what query you execute against Cassandra may vary depending on your requirements. The query used above was taken from this answer to a question about performing a health check on Cassandra.