$ mn create-app my-app --features cassandra
Micronaut Cassandra Configuration
Provides integration between Micronaut and Cassandra
Version: 1.2.0
1 Introduction
The micronaut-cassandra
module includes support for integrating Micronaut services with Cassandra.
2 Setting up Cassandra
Using the CLI
If you are creating your project using the Micronaut CLI, supply the |
To enable the Cassandra configuration, add the following dependency to your application:
compile 'io.micronaut.configuration:micronaut-cassandra:1.2.0'
<dependency>
<groupId>io.micronaut.configuration</groupId>
<artifactId>micronaut-cassandra</artifactId>
<version>1.2.0</version>
</dependency>
Micronaut supports Cassandra configuration by using the Datastax Java Driver. Configuration values can be supplied a property source such as below. The property name is derived from the builder methods in Cluster.Builder (without the prefix). Micronaut will create a Cluster bean. This bean can be then injected into any other Micronaut bean.
ApplicationContext applicationContext = new DefaultApplicationContext("test")
applicationContext.environment.addPropertySource(MapPropertySource.of(
'test',
['cassandra.default.clusterName': "ociCluster",
'cassandra.default.contactPoint': "localhost",
'cassandra.default.port': 9042,
'cassandra.default.maxSchemaAgreementWaitSeconds': 20,
'cassandra.default.ssl': true]
))
applicationContext.start()
Multiple Cluster instances can be configured as follows:
ApplicationContext applicationContext = new DefaultApplicationContext("test")
applicationContext.environment.addPropertySource(MapPropertySource.of(
'test',
['cassandra.default.contactPoint': "localhost",
'cassandra.default.port': 9042,
'cassandra.secondary.contactPoint': "127.0.0.2",
'cassandra.secondary.port': 9043]
))
applicationContext.start()