[英]spring batch metadata in cassandra database
問題很簡單:我可以在 Cassandra 數據庫中為 Spring Batch 創建元數據模式嗎? 如果是,我該怎么做? 我讀過 Spring Batch 需要為此使用 RDBMS 數據庫,並且不支持 No-SQL 數據庫。 這仍然是 Spring Batch 中的限制,我最終如何覆蓋該問題?
由於卡桑德拉不支持鍵的簡單序列,Spring Batch 不支持將其用於作業存儲庫。
可以通過自定義 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...");
}
@豆子:
@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;
}
完整的源代碼可以在 GithubSpring-Batch-with-Cassandra 中找到
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.