【问题标题】:Creating Hector cluster in Java在 Java 中创建 Hector 集群
【发布时间】:2015-10-22 07:42:15
【问题描述】:

我正在尝试使用 Hector 的基本定义来创建 Cassandra 集群。这是我的代码(只有连接和架构部分)。

CassandraHostConfigurator chc = new CassandraHostConfigurator(
       "localhost");
    chc.setMaxActive(20);
    chc.setCassandraThriftSocketTimeout(3000);
    chc.setMaxWaitTimeWhenExhausted(4000);    
    Cluster cluster = HFactory.getOrCreateCluster("mycluster", chc);
    System.out.println("cluster: " + cluster.getKnownPoolHosts(false));
    try{
        KeyspaceDefinition keyspaceDef = cluster.describeKeyspace("sensornetwork");
    } catch (HectorException he){
        ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("sensornetwork",
                                                                     "ColumnFamilyName",
                                                                     ComparatorType.BYTESTYPE);

        KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition("sensornetwork",
                                                                   ThriftKsDef.DEF_STRATEGY_CLASS,
                                                                   1,
                                                                   Arrays.asList(cfDef));    
        cluster.addKeyspace(newKeyspace, true);
   }


    // If keyspace does not exist, the CFs don't exist either. => create them.


    Keyspace keyspace = HFactory.createKeyspace("sensornetwork", cluster);

我基本上是按照 Hector 自己网站上的文档来做到这一点的。

我得到的错误是这个:

线程“main”中的异常 me.prettyprint.hector.api.exceptions.HectorException:所有主机池 记下来。重试负担推给客户端。在 me.prettyprint.cassandra.connection.HConnectionManager.getClientFromLBPolicy(HConnectionManager.java:401) 在 me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:232) 在 me.prettyprint.cassandra.service.ThriftCluster.addKeyspace(ThriftCluster.java:168) 在 com.mycompany.mavenpails2.SpeedLayer.CassandraPrepwork(SpeedLayer.java:62)

显然,我正在创建一个没有工作池连接的集群。我已经更改了端口并尝试了所有方法,但无法使其正常工作。有什么建议吗?

【问题讨论】:

    标签: java cassandra hector


    【解决方案1】:

    很可能“本地主机”没有在听节俭。可能会想要使用像 https://github.com/datastax/java-driver 这样的 cql 客户端。否则请确保您在 cassandra.yaml 中启用了节俭

    【讨论】:

    • 谢谢,那我试试Datastax。
    猜你喜欢
    • 1970-01-01
    • 2017-03-02
    • 2021-02-13
    • 2020-09-24
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多