我们正在设置一致性级别,默认为LOCAL_QUORUM。我们在配置集群时使用它-
Cluster.builder().addContactPoints(environment.getProperty("cassandra.contact-points").split(",")).withPort(port)
.withQueryOptions(
new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(environment.getProperty("cassandra.consistency-level")))
.setSerialConsistencyLevel(ConsistencyLevel.valueOf(environment.getProperty("cassandra.consistency-level"))))
.withAuthProvider(new DsePlainTextAuthProvider(environment.getProperty("cassandra.username"),
environment.getProperty("cassandra.password")));
在application.properties文件中,我们提供的一致性级别为-
cassandra.consistency-level=LOCAL_QUORUM
现在,我们不想对某些查询使用LOCAL_QUORUM。为此,我们按照Here中的说明创建了自定义存储库。
我们在自定义存储库中公开了带有WriteOptions的保存方法-
@NoRepositoryBean
public interface CustomizedUserRepository<T> {
<S extends T> S save( S entity, ConsistencyLevel consistencyLevel);
}
它的实现-
public class UserRepositoryImpl implements CustomizedUserRepository<User> {
@Autowired
CassandraOperations cassandraOperations;
@Override
public <S extends User> S save( S entity, ConsistencyLevel consistencyLevel) {
WriteOptions writeOptions = WriteOptions.builder().consistencyLevel(consistencyLevel).build();
cassandraOperations.insert(entity, writeOptions);
return entity;
}
}
并将其在服务类中称为-
@Override
public User createUser( User user) {
return userRepository.save(user, ConsistencyLevel.ONE);
}
工作正常。
现在,问题是,此实现是否将覆盖默认的(本地仲裁)以保存用户功能?我如何确保它以-
的形式工作我们尝试向集群注册QueryLogger,以检查是否可以在日志中看到一致性级别信息,但它仅打印查询。