This project includes integration between Micronaut and ClickHouse, autocompletion for configuration, health check.
Gradle
implementation "com.github.goodforgod:micronaut-clickhouse:6.0.0"
Maven
<dependency>
<groupId>com.github.goodforgod</groupId>
<artifactId>micronaut-clickhouse</artifactId>
<version>6.0.0</version>
</dependency>
Official JDBC driver provides DataSource:
@Inject
private ClickHouseDataSource clickHouseDataSource;
@Named("clickhouse")
@Inject
private DataSource dataSource;
Official Configuration supports all available ClickHouse driver settings.
Check ClickHouse Official settings file for info about all parameters.
clickhouse:
jdbc:
url: jdbc:clickhouse://localhost:8529/default?compress=1
use-options: true # default - true
options:
user: default
password: default
use-custom-options: true # default - true
custom-options:
my-option: 1
Official R2DBC driver provides ConnectionFactory:
@Named("clickhouse")
@Inject
private ConnectionFactory connectionFactory;
R2DBC configuration example:
clickhouse:
r2dbc:
url: r2dbc:clickhouse:http://localhost:8529/default?compress=1
Health check for ClickHouse is provided for JDBC & R2DBC and is turned on by default.
Micronaut health check is part of Micronaut Health Endpoint.
Example of ClickHouse health:
{
"name": "service",
"status": "UP",
"details": {
"clickhouse-jdbc": {
"name": "clickhouse",
"status": "UP"
},
"clickhouse-r2dbc": {
"name": "clickhouse",
"status": "UP"
}
}
}
Where database name service is connected same as configuration says.
You can explicitly turn off health check or configure it.
endpoints:
health:
clickhouse:
enabled: true # default - true
jdbc:
enabled: true # default - true
timeout: 10000ms # default - 10000ms
retry: 2 # default - 2
r2dbc:
enabled: true # default - true
timeout: 10000ms # default - 10000ms
retry: 2 # default - 2
For testing purposes you can use ClickHouse TestContainer library.
TestContainers allows you to use integration tests against real database in all docker friendly environments, check here for TestContainers.
Starting from version 6.0.0 library ships for Micronaut 4 & Java 17 is required.
Starting from version 3.0.0 library ships for Micronaut 3.
Starting from version 2.1.0 Java 11+ is required.
Starting from version 2.0.0 library ships for Micronaut 2 & Java 1.8 is required.
Last release for Micronaut 1 is version 1.0.2.
This project licensed under the Apache License 2.0 - see the LICENSE file for details.