Package reference page maintained from the source documentation in src/HealthChecks.Cassandra.

Cassandra Health Check

This health check verifies the ability to communicate with Apache Cassandra. It uses the CassandraCSharpDriver library.

NuGet

Nuget

dotnet add package DotNetDiag.HealthChecks.Cassandra

Example Usage

With all of the following examples, you can additionally add the following parameters:

Resolve ICluster from the service provider

void Configure(IHealthChecksBuilder builder)
{
    builder.Services
        .AddSingleton<ICluster>(sp => Cluster.Builder()
            .AddContactPoint("localhost")
            .Build())
        .AddHealthChecks()
        .AddCassandra(sp => sp.GetRequiredService<ICluster>());
}

Connect to a specific keyspace

void Configure(IHealthChecksBuilder builder)
{
    builder.Services
        .AddHealthChecks()
        .AddCassandra(
            sp => sp.GetRequiredService<ICluster>(),
            options: new CassandraHealthCheckOptions { Keyspace = "mykeyspace" });
}

Use a cluster factory inline

void Configure(IHealthChecksBuilder builder)
{
    builder.Services
        .AddHealthChecks()
        .AddCassandra(
            _ => Cluster.Builder().AddContactPoint("localhost").Build(),
            name: "cassandra-db",
            tags: ["cassandra", "db"]);
}