连接Thrift 0.8,Cassandra 1.0.8和C#时出现异常

时间:2012-04-02 17:40:44

标签: c# .net nosql cassandra thrift

我使用Thrift 0.8为Cassandra 1.0.8生成了客户端。然后我尝试了以下示例。 transport.open()传递,但我无法描述_keyspace或set_keyspace

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?

2 个答案:

答案 0 :(得分:2)

Cassandra使用thrift 0.7构建它的thrift绑定,这几乎肯定是你的问题。如果你想构建自己的thrift绑定,你应该使用那个版本的thrift。

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

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

答案 1 :(得分: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()