卡桑德拉的节俭运输异常

时间:2012-12-27 05:29:09

标签: java exception cassandra thrift

我发生了异常,使用带有节俭的cassandra。我想插入一些数据。这是java代码:

package pacan.java.eee;
import java.nio.ByteBuffer;
import org.apache.cassandra.thrift.Cassandra;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.ColumnParent;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.thrift.NotFoundException;
import org.apache.cassandra.thrift.TBinaryProtocol;
import org.apache.cassandra.thrift.TimedOutException;
import org.apache.cassandra.thrift.UnavailableException;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

public class Main {

    private static final String UTF8 = "UTF8";

    /**
     * @param args
     * @throws TException 
     * @throws InvalidRequestException 
     * @throws NotFoundException 
     * @throws TimedOutException 
     * @throws UnavailableException 
     */
    public static void main(String[] args) throws InvalidRequestException, TException, NotFoundException, UnavailableException, TimedOutException {
        TTransport tr = new TFramedTransport(new TSocket("localhost", 7199));
        TProtocol protocol = new TBinaryProtocol(tr);
        Cassandra.Client client = new Cassandra.Client(protocol);
        tr.open();
        client.set_keyspace("keyspace");
        ColumnParent colParent = new ColumnParent("User");
        ByteBuffer rowid = ByteBuffer.wrap("100".getBytes());
        Column column = new Column();
        column.setName("description".getBytes());
        column.setValue("some value".getBytes());
        column.setTimestamp(System.currentTimeMillis());
        client.insert(rowid, colParent, column, ConsistencyLevel.ONE);
        tr.flush();
        tr.close();
    }

}

这是我得到的例外:

Exception in thread "main" org.apache.thrift.transport.TTransportException
    at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:132)
    at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84)
    at org.apache.thrift.transport.TFramedTransport.readFrame(TFramedTransport.java:129)
    at org.apache.thrift.transport.TFramedTransport.read(TFramedTransport.java:101)
    at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84)
    at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:378)
    at org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:297)
    at org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:204)
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:69)
    at org.apache.cassandra.thrift.Cassandra$Client.recv_set_keyspace(Cassandra.java:493)
    at org.apache.cassandra.thrift.Cassandra$Client.set_keyspace(Cassandra.java:480)
    at pacan.java.eee.Main.main(Main.java:37)

请帮忙! =)我已经谷歌了,但无法找到答案。

1 个答案:

答案 0 :(得分:4)

  • 您是否定义/创建了名为“keyspace”的键空间?
  • 您确定在端口7199上运行thrift / rpc(默认为9160)。