簡體   English   中英

Astyanax ClusterContext和/或KeyspaceContext?

[英]Astyanax ClusterContext and/or KeyspaceContext?

當前,我以這種方式啟動ClusterContext:

        AstyanaxContext.Builder builder = new AstyanaxContext.Builder()
            .forCluster(clusterName)
            .forKeyspace(keyspaceName)
            .withAstyanaxConfiguration(getAstyanaxProperties(properties))
            .withConnectionPoolConfiguration(getConnectionPoolProperties(properties))
            .withConnectionPoolMonitor(connectionPoolMonitor);

    clusterContext = builder.buildCluster(ThriftFamilyFactory.getInstance());
    clusterContext.start();
    cluster = clusterContext.getEntity();

在單節點開發環境上運行。 我正在使用ClusterContext,因為我還想創建一個鍵空間,列族等。

我是否還需要啟動KeyspaceContext? 如果是這樣,那么對於鍵空間/列族管理和讀/寫方案而言,單個ClusterContext出於什么目的就足夠了?

如果我確實啟動了KeyspaceContext,則根據連接池監視器,我看到添加了2台並且處於活動狀態的主機。 如果關閉單個Cassandra節點,我仍然會看到1標記為活動節點,這令人困惑。

謝謝。

查看netflix的有關創建鍵空間的文檔。 它表明您使用Keyspace對象創建了鍵空間。 頁面下方還有創建列族的詳細信息。

您用初始化一個AstyanaxContext ,然后用於獲取Keyspace對象。

AstyanaxContext<Keyspace> ctx = new AstyanaxContext.Builder()
    .forKeyspace("MyKeyspace")
    // Additional configuration parameters
    .buildKeyspace(ThriftFamilyFactory.getInstance());
ctx.start();
Keyspace keyspace = ctx.getClient();

然后,您可以創建一個鍵空間(如下)。 請注意,是否尚未創建在forKeyspace(...)函數中指定的鍵空間也沒關系。

// Using simple strategy
keyspace.createKeyspace(ImmutableMap.<String, Object>builder()
    .put("strategy_options", ImmutableMap.<String, Object>builder()
        .put("replication_factor", "1")
        .build())
    .put("strategy_class",     "SimpleStrategy")
        .build()
     );

現在,您可以使用並重復使用此Keyspace來完成所需的任意插入/刪除/ keyspace和列族創建操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM