Cassandra migration library

Cassandra migrations for spring-boot apps

Лицензия

Лицензия

Группа

Группа

com.revinate
Идентификатор

Идентификатор

henicea
Последняя версия

Последняя версия

1.1.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

Cassandra migration library
Cassandra migrations for spring-boot apps
Ссылка на сайт

Ссылка на сайт

https://github.com/revinate/henicea
Система контроля версий

Система контроля версий

https://github.com/revinate/henicea

Скачать henicea

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.revinate/henicea/ -->
<dependency>
    <groupId>com.revinate</groupId>
    <artifactId>henicea</artifactId>
    <version>1.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.revinate/henicea/
implementation 'com.revinate:henicea:1.1.2'
// https://jarcasting.com/artifacts/com.revinate/henicea/
implementation ("com.revinate:henicea:1.1.2")
'com.revinate:henicea:jar:1.1.2'
<dependency org="com.revinate" name="henicea" rev="1.1.2">
  <artifact name="henicea" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.revinate', module='henicea', version='1.1.2')
)
libraryDependencies += "com.revinate" % "henicea" % "1.1.2"
[com.revinate/henicea "1.1.2"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
org.springframework.boot : spring-boot-starter-actuator jar 1.2.4.RELEASE
com.datastax.cassandra : cassandra-driver-core jar 3.0.0

test (2)

Идентификатор библиотеки Тип Версия
org.springframework.boot : spring-boot-starter-test jar 1.2.4.RELEASE
org.assertj : assertj-core jar 3.2.0

Модули Проекта

Данный проект не имеет модулей.

Henicea

Build Status codecov.io Codacy Badge Maven Central Javadocs

Henicea was the sister of Cassandra in the Greek Mythology.

Migration

Henicea provides a simple migration mechanism for Java projects.

Example config class for Spring Boot:

CassandraConfig.java

@Configuration
@Slf4j
public class CassandraConfig {

    @Autowired
    private ResourcePatternResolver resourceResolver;

    @Autowired
    private Environment environment;

    @Bean
    public Migrator migrator() {
        return new Migrator();
    }

    @Bean
    public Cluster cluster() throws IOException {
        Cluster cluster = Cluster.builder()
                .addContactPoints(environment.getProperty("cassandra.contactPoints").split(","))
                .withPort(environment.getProperty("cassandra.port", Integer.class))
                .build();

        log.info("Running migrations");
        migrator().execute(cluster, environment.getProperty("cassandra.keyspace"), getMigrations());

        return cluster;
    }

    @Bean
    public Session session() throws Exception {
        return cluster().connect(environment.getProperty("cassandra.keyspace"));
    }

    private Resource[] getMigrations() throws IOException {
        return resourceResolver.getResources("classpath:/cassandra/*.cql");
    }
}

application.properties

cassandra.contactPoints=cassandra-node1,cassandra-node2
cassandra.port=9042
cassandra.keyspace=myapp

Migration files

The migration file can be named in any pattern. By default the files are sorted by name but the resourceComparator in the Migrator class has a setter to allow custom strategies.

Due to limitations in the driver, each migration file can have only one statement.

Waiting for Cassandra to start

This is a common situation when you use Docker for local development and functional tests, the Cassandra database will start in a separate container and it may take longer to get ready than your application. This library comes with a simple utility to help with retry and exponential back-off.

Cluster cluster = new Retryer()
        .onError((attempt, exception) -> log.warn("Could not connect to cassandra cluster on attempt number {}. Wrapped exception", attempt, exception))
        .withWait(TimeUnit.SECONDS, 1, 2, 4, 8, 10, 10)
        .run(() -> {
            Cluster candidate = Cluster.builder()
                    .addContactPoints("localhost")
                    .withPort(9042)
                    .build();

            candidate.init(); // will throw exception if none of the contact points can be reached

            return candidate;
        });

The run method will throw the last thrown exception if all the attempts failed.

Health check

Henicea provides a simple health check through Spring Boot Actuator. The only requirement is to have a Cassandra Session object in the Spring context.

To auto configure a health check add

@Bean
public CassandraHealthIndicator cassandraHealthIndicator() {
    return new CassandraHealthIndicator();
}

to your Java config class.

com.revinate

Revinate, Inc.

Версии библиотеки

Версия
1.1.2
1.1.1
1.1.0
1.0.0