protected void initCassandraClient() { if(keyspace == null) { keyspace = DEFAULT_KEYSPACE; } if(cluster == null) { cluster = Cluster.builder() .addContactPoint(cassandraContactPoint) .withTimestampGenerator(new AtomicMonotonicTimestampGenerator()) .build(); hasOpenedCluster = true; } // make sure the keyspace exists (create it with default replication settings otherwise) KeyspaceMetadata existingKeyspace = cluster.getMetadata().getKeyspace("camunda"); if(existingKeyspace == null) { final Session session = cluster.connect(); session.execute(String.format("CREATE keyspace %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : " + replicationFactor + " };", keyspace)); session.close(); } if(session == null) { session = cluster.connect(keyspace); } }
/** * @param ip String * @param port String * @param poolingOptions PoolingOptions * @return Cluster Cluster */ private static Cluster createCluster(String ip, String port, PoolingOptions poolingOptions) { return Cluster.builder().addContactPoint(ip).withPort(Integer.parseInt(port)) .withProtocolVersion(ProtocolVersion.V3).withRetryPolicy(DefaultRetryPolicy.INSTANCE) .withTimestampGenerator(new AtomicMonotonicTimestampGenerator()) .withPoolingOptions(poolingOptions).build(); }
@Bean public TimestampGenerator getTimestampGenerator() { return new AtomicMonotonicTimestampGenerator(); }
/** * @param ip String * @param port String * @param userName String * @param password String * @param poolingOptions PoolingOptions * @return Cluster Cluster */ private static Cluster createCluster(String ip, String port, String userName, String password, PoolingOptions poolingOptions) { return Cluster.builder().addContactPoint(ip).withPort(Integer.parseInt(port)) .withProtocolVersion(ProtocolVersion.V3).withRetryPolicy(DefaultRetryPolicy.INSTANCE) .withTimestampGenerator(new AtomicMonotonicTimestampGenerator()) .withPoolingOptions(poolingOptions).withCredentials(userName, password).build(); }