简体   繁体   English

cassandra 数据库中的 spring 批处理元数据

[英]spring batch metadata in cassandra database

The question is quite simple: can I create metadata schema for Spring Batch in Cassandra database?问题很简单:我可以在 Cassandra 数据库中为 Spring Batch 创建元数据模式吗? How can I do this if yes?如果是,我该怎么做? I've read that Spring Batch requires RDBMS database for that and No-SQL databases are not supported.我读过 Spring Batch 需要为此使用 RDBMS 数据库,并且不支持 No-SQL 数据库。 Is that still the limitation in Spring Batch and how can I override that issue eventually?这仍然是 Spring Batch 中的限制,我最终如何覆盖该问题?

由于卡桑德拉不支持键的简单序列,Spring Batch 不支持将其用于作业存储库。

It is possible to extend Spring Batch to support Cassandra by customising ItemReader and ItemWriter.可以通过自定义 ItemReader 和 ItemWriter 来扩展 Spring Batch 以支持 Cassandra。

Reader:读者:

@Override
public Company read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
    final List<Company> companies = cassandraOperations.selectAll(aClass);

    log.debug("Read operations is performing, the object size is  {}", companies.size());

    if (index < companies.size()) {
        final Company company = companies.get(index);
        index++;
        return company;
    }

    return null;
}

Writer:作家:

@Override
public void write(final List<? extends Company> items) throws Exception {
    logger.debug("Write operations is performing, the size is {}" + items.size());
    if (!items.isEmpty()) {
        logger.info("Deleting in a batch performing...");
        cassandraTemplate.deleteAll(aClass);
        logger.info("Inserting in a batch performing...");
        cassandraTemplate.insert(items);
    }

    logger.debug("Items is null...");
}

@Beans: @豆子:

@Bean
public ItemReader<Company> reader(final DataSource dataSource) {
    final CassandraBatchItemReader<Company> reader = new CassandraBatchItemReader<Company>(Company.class);
    return reader;
}

@Bean
public ItemWriter<Company> writer(final DataSource dataSource) {
    final CassandraBatchItemWriter<Company> writer = new CassandraBatchItemWriter<Company>(Company.class);
    return writer;
}

Full source code can be found in GithubSpring-Batch-with-Cassandra完整的源代码可以在 GithubSpring-Batch-with-Cassandra 中找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM