Skip to content

GoodforGod/micronaut-clickhouse

Repository files navigation

Micronaut ClickHouse Configuration

Minimum required Java version Maven Central Java CI Quality Gate Status Coverage Maintainability Rating

This project includes integration between Micronaut and ClickHouse, autocompletion for configuration, health check.

Dependency 🚀

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>

JDBC

Official JDBC driver provides DataSource:

@Inject
private ClickHouseDataSource clickHouseDataSource;

@Named("clickhouse")
@Inject
private DataSource dataSource;

Configuration

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

R2DBC

Official R2DBC driver provides ConnectionFactory:

@Named("clickhouse")
@Inject
private ConnectionFactory connectionFactory;

Configuration

R2DBC configuration example:

clickhouse:
  r2dbc:
    url: r2dbc:clickhouse:http://localhost:8529/default?compress=1

Health Check

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

Testing

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.

Micronaut Compatability

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.

License

This project licensed under the Apache License 2.0 - see the LICENSE file for details.