2012-04-02 28 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()