Java 赫克托尔和安菲尔德的基础知识;卡桑德拉

Java 赫克托尔和安菲尔德的基础知识;卡桑德拉,java,cassandra,hector,Java,Cassandra,Hector,我和卡桑德拉合作-0.8.2。 我正在与赫克托的最新版本合作& 我的java版本是1.6.026 我对卡桑德拉和赫克托很陌生 我想做的是: 1.连接到其他服务器上正在运行的cassandra实例(&N)。我知道它正在运行b/c,我可以通过终端将ssh连接到运行此Cassandra实例的服务器上,并使用完整的功能运行CLI。 2.然后我想连接到一个键空间&创建一个列族,然后通过Hector向该列族添加一个值 我认为我的问题是,此服务器上正在运行的Cassandra实例可能未配置为获取非本地命令。我

我和卡桑德拉合作-0.8.2。 我正在与赫克托的最新版本合作& 我的java版本是1.6.026

我对卡桑德拉和赫克托很陌生

我想做的是: 1.连接到其他服务器上正在运行的cassandra实例(&N)。我知道它正在运行b/c,我可以通过终端将ssh连接到运行此Cassandra实例的服务器上,并使用完整的功能运行CLI。 2.然后我想连接到一个键空间&创建一个列族,然后通过Hector向该列族添加一个值

我认为我的问题是,此服务器上正在运行的Cassandra实例可能未配置为获取非本地命令。我想我的下一步将是在我正在工作的cpu上添加一个Cassandra的本地实例,并尝试在本地执行此操作。你觉得怎么样

以下是我的Java代码:

import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
import me.prettyprint.hector.api.ddl.ComparatorType;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;

    public class MySample {


        public static void main(String[] args) {


            Cluster cluster = HFactory.getOrCreateCluster("Test Cluster", "xxx.xxx.x.41:9160");
            Keyspace keyspace =  HFactory.createKeyspace("apples", cluster);
            ColumnFamilyDefinition cf = HFactory.createColumnFamilyDefinition("apples","ColumnFamily2",ComparatorType.UTF8TYPE);
            StringSerializer stringSerializer = StringSerializer.get();
            Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);
            mutator.insert("jsmith", "Standard1", HFactory.createStringColumn("first", "John"));
}
}

提前感谢您的帮助。

您得到的例外是

why:Keyspace apples does not exist
在代码中,此行实际上并不创建键空间

Keyspace keyspace =  HFactory.createKeyspace("apples", cluster);
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("MyKeyspace", "ColumnFamilyName", ComparatorType.BYTESTYPE);

KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition("MyKeyspace", ThriftKsDef.DEF_STRATEGY_CLASS,  replicationFactor, Arrays.asList(cfDef));

// Add the schema to the cluster.
// "true" as the second param means that Hector will block until all nodes see the change.
cluster.addKeyspace(newKeyspace, true);
如上所述,这是定义键空间所需的代码

Keyspace keyspace =  HFactory.createKeyspace("apples", cluster);
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("MyKeyspace", "ColumnFamilyName", ComparatorType.BYTESTYPE);

KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition("MyKeyspace", ThriftKsDef.DEF_STRATEGY_CLASS,  replicationFactor, Arrays.asList(cfDef));

// Add the schema to the cluster.
// "true" as the second param means that Hector will block until all nodes see the change.
cluster.addKeyspace(newKeyspace, true);

我们也在维基上看到了一些可能会有所帮助的信息。

您是否注意到
键空间苹果不存在
?。感谢您的回复。我的问题是,当我尝试运行此代码时,replicationFactor似乎未定义。我完全复制了此处提供的内容:,并更改了相应的名称变量。知道为什么“复制因子”没有定义吗?我没有其他东西可以导入到这个类中。您遇到编译器错误了吗?你能加上int replicationfactor=1这行吗;谢谢我解决了我的问题!createKeyspace和createKeyspaceDefinition之间有什么区别?为什么需要Keyspace对象而不是KeyspaceDefinition?