0

我最近开始使用 Cassandra 数据库,并且正在使用 Netflix 客户端来填充和读取 Cassandra 数据库中的数据。

我有一个带有四个节点的集群。我已经创建了这样的键空间-

        create keyspace profilekeyspace
        with placement_strategy = 'NetworkTopologyStrategy'
        and strategy_options = {DC2 : 1, DC1 : 1}
        and durable_writes = true;

我的专栏家族名称是-profile_columnfamily

这是我的四个节点-

      lp-host01.vip.slc.qa.host.com:9160
      lp-host02.vip.slc.qa.host.com:9160
      lp-host03.vip.phx.qa.host.com:9160
      lp-host04.vip.phx.qa.host.com:9160

现在我只使用上面的一个节点来连接 Cassandra 数据库并填充数据。但是我的 DBA 说,您需要使用所有四个节点来建立连接。

private AstyanaxContext<Keyspace> context;

private CassandraAstyanaxConnection() {

    context = new AstyanaxContext.Builder()
    .forCluster("TEST CLUSTER")
    .forKeyspace("PROFILE")
    .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()     
        .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
    )
    .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
        .setPort(9160)
        .setMaxConnsPerHost(1)
        .setSeeds("lp-host01.vip.slc.qa.host.com:9160:9160")//using only node from above to make the connection
    )
    .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()     
        .setCqlVersion("3.0.0")
        .setTargetCassandraVersion("1.2"))
    .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
    .buildKeyspace(ThriftFamilyFactory.getInstance());

    context.start();
    keyspace = context.getEntity();

    emp_cf = ColumnFamily.newColumnFamily(
        "PROFILE_COLUMNFAMILY",
        StringSerializer.get(),
        StringSerializer.get());
}

现在我不确定如何使用所有四个节点使用 Netflix 客户端进行连接?任何人都可以帮助我吗?

谢谢您的帮助。

4

1 回答 1

2

种子列表是一个逗号分隔的列表。所以你可以在 setSeeds 调用中添加其余部分:

setSeeds("server1:9160,server2:9160,server3:9160")

此外,Astyanax 将发现环中的其他服务器。您只需要列出一个即可发现所有其他服务器,但如果该服务器关闭,您需要列出更多。它非常类似于 cassandra.yaml 中的种子列表。

请注意,您已经复制了行中的端口:

.setSeeds("lp-host01.vip.slc.qa.host.com:9160:9160")

于 2013-04-23T18:57:15.673 回答