1 Cassandra Astyanax Plugin - Reference Documentation
Authors: Bob Florian
Version: 0.4.3
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 connectionPoolType = com.netflix.astyanax.connectionpool.impl.ConnectionPoolType.TOKEN_AWARE connectionPoolMonitor = new com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor() discoveryType = com.netflix.astyanax.connectionpool.NodeDiscoveryType.RING_DESCRIBE retryPolicy = new com.netflix.astyanax.retry.RetryNTimes(3) connectTimeout = 2000, socketTimeout = 11000, maxTimeoutWhenExhausted = 2000, maxTimeoutCount = 3, timeoutWindow = 10000, connectionPoolName = "MyConnectionPool" defaultReadConsistencyLevel = "CL_ONE" defaultWriteConsistencyLevel = "CL_ONE" columnFamilies { AstyanaxTest { LongPropertyObject = new ColumnFamily("LongPropertyObject", StringSerializer.get(), LongSerializer.get()) } } } } defaultCluster = 'standard' }
Property | Required | Meaning |
---|---|---|
seeds | yes | String of the form "host:port, 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. |
connectionPoolType | no | The connection pool type. Defaults to ROUND_ROBIN. Other values are TOKEN_AWARE, ROUND_ROBIN, and BAG |
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 |
connectTimeout | no | Socket connect timeout in milliseconds |
socketTimeout | no | Socket read/write timeout in milliseconds |
maxTimeoutCount | no | Number of allowed timeouts within timeoutWindow milliseconds |
timeoutWindow | no | Shut down a host if it times out too many times within this window |
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 |
columnFamilies | no | Two level Map specifying the serializers to be used for the column row and name, whenever a string is specified as the column family rather than a com.netflix.astyanax.model.ColumnFamily object. The key of the outer map is the key space name and the inner map is the column family name. |
userName | no | username for authentication to Cassandra. |
password | no | password for authentication to Cassandra |