Cassandra Java driver: how many contact points is reasonable?

后端 未结 4 1549
失恋的感觉
失恋的感觉 2020-12-14 09:30

In Java I connect to Cussandra cluster as this:

Cluster cluster = Cluster.builder().addContactPoints(\"host-001\",\"host-002\").build();

Do

4条回答
  •  心在旅途
    2020-12-14 09:55

    Documentation from DataStax

    public Cluster.Builder addContactPoint(String address)
    

    Adds a contact point.

    Contact points are addresses of Cassandra nodes that the driver uses to discover the cluster topology. Only one contact point is required (the driver will retrieve the address of the other nodes automatically), but it is usually a good idea to provide more than one contact point, because if that single contact point is unavailable, the driver cannot initialize itself correctly.

    Note that by default (that is, unless you use the withLoadBalancingPolicy(com.datastax.driver.core.policies.LoadBalancingPolicy)) method of this builder), the first successfully contacted host will be use to define the local data-center for the client. If follows that if you are running Cassandra in a multiple data-center setting, it is a good idea to only provided contact points that are in the same datacenter than the client, or to provide manually the load balancing policy that suits your need.

    Parameters:
        address - the address of the node to connect to
    Returns:
        this Builder.
    Throws:
        IllegalArgumentException - if no IP address for address could be found
        SecurityException - if a security manager is present and permission to resolve the host name is denied.
    

    From what I understand, you should just add a single contact point and the driver will discover the rest. Hope that helps. I personally use hector you should look into that too.

提交回复
热议问题