I'm doing some work with Cassandra and the Thrift libraries. I realize these are very early libraries and will (undoubtedly) change at some point.
I've been using the following link for help with setting up my C# code to write and read to and from my Cassandra server (which I have running in an Ubuntu Server instance in my local VirtualBox). I've confirmed that the trivial read / write functionality works.
Where I'm having a problem is executing the following method (which was generated for me using the thrift.definition file that came with Cassandra):
public void send_get_count(string keyspace, string key, ColumnParent column_parent, ConsistencyLevel consistency_level)
Here's my setup code:
TTransport _transport;
TProtocol _protocol;
Cassandra.Client _client;
public Test()
{
_transport = new TSocket("192.168.56.101", 9160);
_protocol = new TBinaryProtocol(_transport);
_client = new Cassandra.Client(_protocol);
}
My calling code looks like so:
public void GetAllBlogEntries()
{
var timestamp = DateTime.Now.Millisecond;
var keyspace = "Keyspace1";
var utf8Encoding = System.Text.Encoding.UTF8;
var columnParent = new ColumnParent() {Column_family = "BlogEntries"};
var predicate = new SlicePredicate()
{
Slice_range = new SliceRange()
{
Start = new byte[0],
Finish = new byte[0],
Count = 10,
Reversed = false
}
};
var results = _client.get_range_slice(keyspace, columnParent, predicate, "", "", 5, ConsistencyLevel.ONE);
foreach(var slice in results)
{
Console.WriteLine("Found Key: {0}", slice.Key);
foreach(var resultColumn in slice.Columns)
{
var column = resultColumn.Column;
Console.WriteLine("\tName: {0}, value: {1}",
utf8Encoding.GetString(column.Name),
utf8Encoding.GetString(column.Value));
}
}
}
The first line of this method is where I am getting my exception:
oprot_.WriteMessageBegin(new TMessage("get_count", TMessageType.Call, seqid_));
And here is the exception:
Thrift.Transport.TTransportException: Cannot write to null outputstream at Thrift.Transport.TStreamTransport.Write(Byte[] buf, Int32 off, Int32 len) at Thrift.Protocol.TBinaryProtocol.WriteI32(Int32 i32) at Thrift.Protocol.TBinaryProtocol.WriteMessageBegin(TMessage message) at Apache.Cassandra.Cassandra.Client.send_get_range_slice(String keyspace, ColumnParent column_parent, SlicePredicate predicate, String start_key, String finish_key, Int32 row_count, ConsistencyLevel consistency_level) in Cassandra.cs: line 341 at Apache.Cassandra.Cassandra.Client.get_range_slice(String keyspace, ColumnParent column_parent, SlicePredicate predicate, String start_key, String finish_key, Int32 row_count, ConsistencyLevel consistency_level) in Cassandra.cs: line 335 at CassandraDemo.Models.Test.GetAllBlogEntries() in Test.cs: line 212 at CassandraDemo.Tests.Models.TestTest.Test_GetAllBlogEntries_Success() in TestTest.cs: line 42
Any ideas?
You need to call Open() on the transport.