【问题标题】:Exception while Connecting Thrift 0.8 , Cassandra 1.0.8 and C#连接 Thrift 0.8、Cassandra 1.0.8 和 C# 时出现异常
【发布时间】:2012-04-16 09:17:50
【问题描述】:

我使用 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?

【问题讨论】:

标签: c# .net nosql cassandra thrift


【解决方案1】:

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

正如 psanford 所说,您很可能使用的是更高级别的客户端。见:

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

【讨论】:

    【解决方案2】:

    问题在于 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()

    【讨论】:

      猜你喜欢
      • 2012-01-16
      • 2012-03-04
      • 2015-12-30
      • 2014-11-03
      • 1970-01-01
      • 2020-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多