Astyanax Cassandra Client - Reference Documentation
Authors: Bob Florian
Version: 0.2.0
Table of Contents
1 Cassandra Astyanax Plugin
The Cassandra Astyanax Plugin simplifies integration of the Netflix developed Astyanax Cassandra client into a Grails application. In addition to encapsulating the client into a Grails service the plugin adds several dynamic methods that make using the client from the Groovy language more convenient for typical use cases.1.1 Getting Started
The plugin supports any number of Cassandra clusters, which may have different connection pool implementations, default consistency levels, and retry policies. To create a simple configuration with one cluster add the following to your project's Config.groovy file:astyanax { clusters { standard { seeds = ["localhost:9160"] defaultKeyspace = "AstyanaxTest" } } defaultCluster = 'standard' }
astyanaxService.keyspace().prepareQuery("Standard1") .getKey("some-row-key") .execute() .result
astyanaxService.withKeyspace {keyspace -> keyspace.prepareQuery("Standard1") .getKey("some-row-key") .execute() .result }
astyanaxService.keyspace().prepareQuery(new ColumnFamily("Standard1", StringSerializer.get(), LongSerializer.get())) .getKey("some-row-key") .execute() .result
astyanaxService.keyspace("AstyanaxTest2").prepareQuery("Standard2") .getKey("some-row-key") .execute() .result
astyanax { clusters { standard { seeds = ["localhost:9160"] defaultKeyspace = "AstyanaxTest" } anotherCluster { seeds = ["111.222.333.444:9160"] } } defaultCluster = 'standard' }
astyanaxService.keyspace("TheKeyspace", "anotherCluster").prepareQuery("TestCF1") .getKey("some-row-key") .execute() .result
1.2 Configuration Options
The complete set of configuration options supported by the plugin (with their default values) are shown in the following configuration:astyanax { clusters { standard { seeds = ["localhost:9160"] defaultKeyspace = "AstyanaxTest" port = 9160 maxConsPerHost = 10 retryCount = 3 connectionPoolMonitor = new com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor() discoveryType = com.netflix.astyanax.connectionpool.NodeDiscoveryType.NONE retryPolicy = new com.netflix.astyanax.retry.RetryNTimes(3) connectionPoolName = "MyConnectionPool" defaultReadConsistencyLevel = "CL_ONE" defaultWriteConsistencyLevel = "CL_ONE" } } defaultCluster = 'standard' }
Property | Required | Meaning |
---|---|---|
seeds | yes | Array of node strings of the form "host:port" that Astyanax will use in quering Cassandra |
defaultKeyspace | no | Name of the keyspace to use if one is not specified in the service call |
port | no | Port number used for communicating to Cassandra nodes. Defaults to 9160. |
maxConsPerHost | no | The maximum number of connections to be created for any one node. Defaults to 10. |
retryCount | no | The number of times Astyanax will retry a call before failing. Has not effect if the retryPolicy property is set. Defaults to 3. |
connectionPoolMonitor | no | The connection pool monitor implementation. Defaults to new com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor |
discoveryType | no | The method of discovering new nodes. Defaults to NONE (no discovery). Other values are RING_DESCRIBE, DISCOVERY_SERVICE, and TOKEN_AWARE |
retryPolicy | no | The retry policy to use. Defaults to RetryNTimes. Others values include RunOnce, ConstantBackoff, ExponentialBackoff, BoundedExponentialBackoff, and SleepingRetryPolicy |
connectionPoolName | no | Name used to identify the connection pool. Defaults to the astyanax.clusters configuration key, i.e. "standard" in this example |
defaultReadConsistencyLevel | no | Default consistency level used when reading from the cluster. This value can be overwritten on the Query operations. |
defaultWriteConsistencyLevel | no | Default consistency level used when reading from the cluster. This value can be overwritten on MutationBatch operation |