$ mn create-app my-app --features cassandra
Micronaut Cassandra
Provides integration between Micronaut and Cassandra
Version:
1 Introduction
The micronaut-cassandra
module includes support for integrating Micronaut services with Cassandra.
2 Release History
For this project, you can find a list of releases (with release notes) here:
3 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:
implementation("io.micronaut.cassandra:micronaut-cassandra:5.1.1")
<dependency>
<groupId>io.micronaut.cassandra</groupId>
<artifactId>micronaut-cassandra</artifactId>
<version>5.1.1</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 CqlSessionBuilder. Micronaut will create a CqlSession bean. This bean can be then injected into any other Micronaut bean.
cassandra:
default:
advanced:
metadata:
schema:
enabled: false
basic:
contact-points:
- "127.0.0.1:9042"
- "127.0.0.2:8042"
load-balancing-policy:
local-datacenter: datacenter1
Multiple Cluster instances can be configured as follows:
cassandra:
default:
advanced:
metadata:
schema:
enabled: false
basic:
contact-points:
- "127.0.0.1:9042"
load-balancing-policy:
local-datacenter: datacenter1
secondary:
advanced:
metadata:
schema:
enabled: false
basic:
contact-points:
- "127.0.0.1:9043"
load-balancing-policy:
local-datacenter: datacenter2
4 Health Checks
When the cassandra
module is activated a CassandraHealthIndicator is
activated resulting in the /health
endpoint and CurrentHealthStatus
interface resolving the health of the Cassandra cluster.
"cassandra": {
"status": "UP",
"details": {
"session": "OPEN",
"cluster_name": "Test Cluster",
"nodes_count": 1,
"nodes_state": {
"UP": 1
}
"nodes (10 max.)": {
"4a9e6e53-7eed-4c1f-b497-4f93715b2b04": {
"endpoint": "localhost/0:0:0:0:0:0:0:1:32834",
"broadcast_address": "/172.17.0.3",
"state": "UP",
"distance": "LOCAL",
"open_connections": "2",
"cassandra_version": "3.11.2",
"datacenter": "datacenter1",
"rack": "rack1",
"uptime_ms": "1593462452206",
"is_reconnecting": "false"
}
}
}
}
To disable the Cassandra health indicator entirely, add endpoints.health.cassandra.enabled: false .
|
See the section on the Health Endpoint for more information.
5 Additional Notes
The Datastax Cassandra driver is configured using lightbend/config under the field datastax-java-driver.\*
.
The equivalent bean created for micronaut is mapped under the cassandra..
. fields provided in your application.conf
, but the bean will fallback on the datastax-java-driver.\*
values if they are present.
These config values are provided to the CqlSession under the hood. Datastax does not provide a class that maps to all the various possible config keys, but a full list of values that can be provided can be found in the DefaultDriverOption enum.
lightbend/config
- application.confdatastax-java-driver {
basic {
contact-points = [ "1.2.3.4:9042", "5.6.7.8:9042" ]
load-balancing-policy.local-datacenter = datacenter1
}
}
cassandra:
default:
basic:
contact-points:
- "127.0.0.1:9042"
- "5.6.7.8:9042"
load-balancing-policy:
local-datacenter: datacenter1
6 GraalVM support
Micronaut Cassandra is compatible with GraalVM so it is possible to create native images without any additional configuration.
See the section on GraalVM in the user guide for more information. |
7 Repository
You can find the source code of this project in this repository: