Skip to content

Hamdiakoguz/cassandra-sharp

 
 

Repository files navigation

cassandra-sharp - high performance .NET driver for Apache Cassandra

The philosophy of cassandra-sharp is to be really simple and fast: no Linq provider, no complex API. Just CQL, simple object mapping and great performance :)

Starting from version 2, only CQL 3 binary protocol is supported and as a consequence, Cassandra 1.2+ is required. Also, only .NET 4.0+ is supported. If you are looking for a Thrift compatible driver, or have to use Cassandra 1.0/1.1 or require .NET 3.5 support, please consider using version 0.6.4 of cassandra-sharp.

cassandra-sharp supports async operations exposed as Rx subscriptions or TPL tasks. Efficient memory usage can be achieve using the push model of Rx.

A command line tool is also available (cqlplus) to access a Cassandra cluster. It's also a great tool to understand what's happening under the cover.

Features

  • async operations (TPL tasks / Rx subscriptions)
  • Rx interface (IObservable / IObserver) for result streaming
  • TPL Task (compatible with C# 5 async) for future operations
  • Linq friendly
  • extensible rowset mapping (poco and map provided out of the box)
  • blazing fast object marshaler (dynamic gen'ed code)
  • robust connection handling (connection recovery supported)
  • ability to understand performance issues (client and server side)
  • multiple extension points
  • command line tool (cqlplus)
  • .NET 4.0+ support

Getting binaries

Binaries are available through NuGet : http://www.nuget.org/packages/cassandra-sharp

Zip archive are also available at Google Code (since GitHub removed binaries uploads) : http://code.google.com/p/cassandra-sharp/downloads/list

How to build

To build cassandra-sharp, load cassandra-sharp.sln in Visual Studio 2012. To build from command line and to regenerate thrift proxy, use Build.cmd.

Sample configuration

<configSections>
	<section name="CassandraSharp" type="CassandraSharp.SectionHandler, CassandraSharp.Interfaces" />
</configSections>

<CassandraSharp>
	<Cluster name="TestCassandra">
		<Endpoints>
			<Server>localhost</Server>
		</Endpoints>
	</Cluster>
</CassandraSharp>

Sample client

public class SchemaKeyspaces
{
    public bool DurableWrites { get; set; }

    public string KeyspaceName { get; set; }

    public string StrategyClass { get; set; }

    public string StrategyOptions { get; set; }
}

public static class Sample
{
    private static void DisplayKeyspace(SchemaKeyspaces ks)
    {
        Console.WriteLine("DurableWrites={0} KeyspaceName={1} strategy_Class={2} strategy_options={3}",
                          ks.DurableWrites,
                          ks.KeyspaceName,
                          ks.StrategyClass,
                          ks.StrategyOptions);
    }

    public static async Task QueryKeyspaces()
    {
        XmlConfigurator.Configure();
        using (ICluster cluster = ClusterManager.GetCluster("TestCassandra"))
        {
            var cmd = cluster.CreatePocoCommand();

            const string cqlKeyspaces = "SELECT * from system.schema_keyspaces";

            // async operation with streaming
            cmd.Execute<SchemaKeyspaces>(cqlKeyspaces).Subscribe(DisplayKeyspace);

            // future
            var kss = await cmd.Execute<SchemaKeyspaces>(cqlKeyspaces).AsFuture();
            foreach (var ks in kss)
            {
                DisplayKeyspace(ks);
            }
        }

        ClusterManager.Shutdown();
    }
}

Thanks

JetBrains provided a free licence of Resharper for the cassandra-sharp project. Big thanks for the awesome product.

This projects also relies on the following third parties:

githalytics.com alpha

About

high performance .NET driver for Apache Cassandra

Resources

Stars

Watchers

Forks

Packages

No packages published