Cassandra群集恢复 [英] Cassandra Cluster Recovery

查看:494
本文介绍了Cassandra群集恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Boot应用程序使用Spring Data for Cassandra。其中一个要求是,即使Cassandra集群不可用,应用程序也将启动。应用程序记录情境,并且其所有端点将无法正常工作,但应用程序未关闭。在此期间应重试连接到群集。当集群可用时,应用程序应该开始正常运行。
如果我能够在应用程序启动期间连接,并且集群在此之后不可用,cassandra java驱动程序能够管理重试。
如何在应用程序启动期间管理重试,并仍使用Spring Data中的Cassandra存储库?

I have a Spring Boot Application that uses Spring Data for Cassandra. One of the requirements is that the application will start even if the Cassandra Cluster is unavailable. The Application logs the situation and all its endpoints will not work properly but the Application does not shutdown. It should retry to connect to the cluster during this time. When the cluster is available the application should start to operate normally. If I am able to connect during the application start and the cluster becomes unavailable after that, the cassandra java driver is capable of managing the retries. How can I manage the retries during application start and still use Cassandra Repositories from Spring Data?

Thanx

推荐答案

如果Apache Cassandra不可用,但是需要定义 Session code> CassandraTemplate 自带 @Lazy 。这些bean开箱即用 CassandraAutoConfiguration 提供,但是被热切地初始化(默认行为),创建一个 Session Session 需要连接到Cassandra,这将防止启动,如果它没有被懒惰初始化。

It is possible to start a Spring Boot application if Apache Cassandra is not available but you need to define the Session and CassandraTemplate beans on your own with @Lazy. The beans are provided out of the box with CassandraAutoConfiguration but are initialized eagerly (default behavior) which creates a Session. The Session requires a connection to Cassandra which will prevent a startup if it's not initialized lazily.

以下代码将懒惰地初始化资源:

The following code will initialize the resources lazily:

@Configuration
public class MyCassandraConfiguration {

    @Bean
    @Lazy
    public CassandraTemplate cassandraTemplate(@Lazy Session session, CassandraConverter converter) throws Exception {
        return new CassandraTemplate(session, converter);
    }

    @Bean
    @Lazy
    public Session session(CassandraConverter converter, Cluster cluster,
            CassandraProperties cassandraProperties) throws Exception {
        CassandraSessionFactoryBean session = new CassandraSessionFactoryBean();
        session.setCluster(cluster);
        session.setConverter(converter);
        session.setKeyspaceName(cassandraProperties.getKeyspaceName());
        session.setSchemaAction(SchemaAction.NONE);
        return session.getObject();
    }
}

这篇关于Cassandra群集恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆