我们可以使用Datastax mapper为Cassandra(Java驱动程序)执行批处理语句吗?我想异步执行批处理语句而不会阻塞结果。有什么例子吗?
答案 0 :(得分:2)
Mapper接口具有基本操作的异步变体(saveAsync
等)。
如果您正在使用访问者,请指定返回类型ResultSetFuture
或ListenableFuture<T>
以使查询异步。这是一个例子from our tests:
// Note that the following method will be asynchronous (it will use executeAsync
// underneath) because it's return type is a ListenableFuture. Similarly, we know
// that we need to map the result to the Post entity thanks to the return type.
@Query("SELECT * FROM posts WHERE user_id=?")
@QueryParameters(consistency="QUORUM")
public ListenableFuture<Result<Post>> getAllAsync(UUID userId);