我正在使用 Cassandra 和 Thrift 库做一些工作。我意识到这些是非常早期的库,并且(毫无疑问)会在某个时候发生变化。
我一直在使用以下 link寻求帮助设置我的 C# 代码以写入和读取我的 Cassandra 服务器(我在本地 VirtualBox 的 Ubuntu 服务器实例中运行)。我已确认普通的读/写功能有效。
我遇到问题的地方是执行以下方法(这是使用 Cassandra 附带的 thrift.definition 文件为我生成的):
public void send_get_count(string keyspace, string key, ColumnParent column_parent, ConsistencyLevel consistency_level)
这是我的设置代码:
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);
}
我的调用代码如下所示:
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));
}
}
}
此方法的第一行是我得到异常的地方:
oprot_.WriteMessageBegin(new TMessage("get_count", TMessageType.Call, seqid_));
这里是异常(exception):
Thrift.Transport.TTransportException:无法写入空输出流 在 Thrift.Transport.TStreamTransport.Write(Byte[] buf,Int32 off,Int32 len) 在 Thrift.Protocol.TBinaryProtocol.WriteI32(Int32 i32) 在 Thrift.Protocol.TBinaryProtocol.WriteMessageBegin(TMessage 消息) 在 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) 在 Cassandra.cs 中:第 341 行 在 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) 在 Cassandra.cs 中:第 335 行 在 Test.cs 中的 CassandraDemo.Models.Test.GetAllBlogEntries():第 212 行 在 TestTest.cs 中的 CassandraDemo.Tests.Models.TestTest.Test_GetAllBlogEntries_Success():第 42 行
有什么想法吗?
最佳答案
您需要在传输上调用 Open()。
关于c# - 节俭.Transport.TTransportException : Cannot write to null outputstream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2411127/