使用Spring Batch写入Cassandra数据库 [英] Using Spring Batch to write to a Cassandra Database

查看:19
本文介绍了使用Spring Batch写入Cassandra数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我可以通过以下代码连接到Cassandra:

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;

public static Session connection() {
    Cluster cluster = Cluster.builder()
        .addContactPoints("IP1", "IP2")
        .withCredentials("user", "password")
        .withSSL()
        .build();
    Session session = null;
    try {
        session = cluster.connect("database_name");
        session.execute("CQL Statement");
    } finally {
        IOUtils.closeQuietly(session);
        IOUtils.closeQuietly(cluster);
    }
    return session;
}

问题是我需要在Spring批处理项目中写入Cassandra。大多数初学者工具包似乎都使用JdbcBatchItemWriter从块写入MySQL数据库。这个是可能的吗?JdbcBatchItemWriter似乎无法连接到Cassandra数据库。

当前项目写入器代码如下:

@Bean
public JdbcBatchItemWriter<Person> writer() {
    JdbcBatchItemWriter<Person> writer = new JdbcBatchItemWriter<Person>();
    writer.setItemSqlParameterSourceProvider(new 
        BeanPropertyItemSqlParameterSourceProvider<Person>());
    writer.setSql("INSERT INTO people (first_name, last_name) VALUES 
        (:firstName, :lastName)");
    writer.setDataSource(dataSource);
    return writer;
}

推荐答案

Spring data Cassandra为Cassandra提供存储库抽象,您应该能够将其与RepositoryItemWriter结合使用,以便从Spring批处理写入到Cassandra。

这篇关于使用Spring Batch写入Cassandra数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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