2012-04-02 72 views
1

我使用Thrift 0.8为Cassandra 1.0.8生成客户端。然后我尝试了下面的例子。该transport.open()传递,但我不能describe_keyspace或set_keyspace连接Thrift 0.8,Cassandra 1.0.8和C时的异常#

TTransport transport = new TBufferedTransport(new TSocket("localhost", 9160)); 
      TProtocol protocol = new TBinaryProtocol(transport); 
      Cassandra.Client client = new Cassandra.Client(protocol); 

      Console.WriteLine("Opening connection"); 

      try 
       { 
       transport.Open(); 
       } 
      catch (Exception e) 
       { 
       Console.WriteLine("error connecting..."); 
       return; 
       } 

      KsDef def = client.describe_keyspace("nm_example"); // error here 
      client.set_keyspace("nm_example");// error here 

这是个例外,我得到

An unhandled exception of type 'Thrift.Transport.TTransportException' occurred in Thrift.dll 

Additional information: Cannot read, Remote side has closed 

我可以连接到使用CLI密钥空间。我在做什么不对?客户端是否只能使用某些版本?有人使用Thrift和C#成功连接到最新的Cassandra吗?

+3

你真的应该使用更高级别的库,而不是直接使用thrift。我建议你看看http://code.google.com/p/cassandra-sharp/ – psanford 2012-04-02 18:15:42

回答

2

卡桑德拉建立它的节俭绑定使用节俭0.7这几乎肯定是你的问题。如果你想建立你自己的节俭绑定,你应该使用那个版本的节俭。

正如psanford提到的,您应该最有可能使用更高级别的客户端。请参阅:

http://wiki.apache.org/cassandra/ClientOptions

1

的问题是与transport.Open() 下面的作品,

TSocket socket = null; 
    TTransport transport = null; 

    socket = new TSocket("localhost", 9160); 


    transport = new TFramedTransport(socket); 
    TProtocol protocol = new TBinaryProtocol(transport); 
    CassandraClient cassandraClient = new CassandraClient(protocol); 
    cassandraClient.InputProtocol.Transport.Open(); 

    string s = cassandraClient.describe_cluster_name(); 
    List<KsDef> keyspaces = cassandraClient.describe_keyspaces(); 

使用cassandraClient.InputProtocol.Transport.Open();而不是transport.open()

相关问题