Database Reference
In-Depth Information
and create our class. We will also add a private instance variable for our cluster
and our session. Listing 9.8 shows the class creation.
Listing 9.8 Creating a Sample C# Class
Click here to view code image
using Cassandra;
using System;
namespace CassandraExample {
class SampleApp {
private Cluster cluster;
private Session session;
}
}
Connecting
When connecting to the cluster, we need to specify only a single node. The driver
will automatically query for information about the cluster and build a connection
to each of the nodes in the cluster. Listing 9.9 shows how to connect to a cluster
and print out information about the connections to the cluster.
Listing 9.9 Using C# to Connect to a Cluster
Click here to view code image
public void Connect(String node) {
cluster =
Cluster.Builder().AddContactPoint(node).Build();
session = cluster.Connect();
Metadata metadata = cluster.Metadata;
Console.WriteLine("Cluster: " +
metadata.ClusterName.ToString());
foreach (Host host in metadata.AllHosts()) {
Console.WriteLine("Host: " + host.Address);
}
}
 
 
Search WWH ::




Custom Search