问题很简单:我可以在Cassandra数据库中为Spring Batch创建元数据模式吗?如果是的话我怎么能这样做? 我已经读过Spring Batch需要RDBMS数据库并且不支持No-SQL数据库。这仍然是Spring Batch的限制,我最终如何覆盖该问题?
答案 0 :(得分:0)
由于Casandra不支持密钥的简单序列,因此Spring Batch不支持将其用于作业存储库。
答案 1 :(得分:0)
通过自定义ItemReader和ItemWriter,可以扩展Spring Batch以支持Cassandra。
阅读器:
@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;
}
作家:
@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;
}
完整的源代码可以在Github Spring-Batch-with-Cassandra
中找到