public static Cluster connectToCluster()

in java/datastax-v3/connection-vpc-endpoint/src/main/java/software/aws/mcs/example/OrderFetcher.java [41:71]


    public static Cluster connectToCluster(String region, List<InetSocketAddress> contactPoints) {
        // VPC endpoints appear as a single, infinitely scalable and highly available node. To optimize for throughput
        // and availability we recommend increasing the number of local connections to at least 9. For more info
        // on throughput tuning, see https://docs.aws.amazon.com/keyspaces/latest/devguide/functional-differences.html#functional-differences.query-throughput-tuning
        PoolingOptions poolingOptions = new PoolingOptions(); // [1]
        poolingOptions
                .setConnectionsPerHost(HostDistance.LOCAL,  9 /* min connections */, 9 /* max connections */);

        // The default retry policy in the driver retries the next node. However, as VPC endpoints appear as single nodes,
        // the default retry policy essentially has no retries. To re-enable retries, we recommend using a retry policy
        // that defaults the retry same node. Retries are helpful for handling scaling scenarios where an application
        // may have exceeded the table capacity ahead of Keyspaces scaling up to accommodate the traffic. For more
        // on serverless resource management, see https://docs.aws.amazon.com/keyspaces/latest/devguide/ReadWriteCapacityMode.html
        AmazonKeyspacesRetryPolicy retryPolicy = new AmazonKeyspacesRetryPolicy();

        SigV4AuthProvider provider = new SigV4AuthProvider(region);
        Cluster cluster = Cluster.builder()
                .addContactPointsWithPorts(contactPoints)
                .withPort(KEYSPACES_PORT)
                .withAuthProvider(provider)
                .withSSL()
                .withPoolingOptions(poolingOptions)
                .withRetryPolicy(retryPolicy)
                .build();

        // To enable retries for writes, enable query idempotence. This can also be done per request, if only some writes
        // idempotent.
        cluster.getConfiguration().getQueryOptions().setDefaultIdempotence(true);

        return cluster;
    }