cassandra java客户端_Cassandra的Java客户端的另一个选择---Pelops

除了Hector以外,基于Java的cassandra的客户端还有很多,Pelops就是其中之一。

参考网站:

测试代码如下:

import org.apache.cassandra.thrift.Column;

import org.apache.cassandra.thrift.ConsistencyLevel;

import org.scale7.cassandra.pelops.Cluster;

import org.scale7.cassandra.pelops.Mutator;

import org.scale7.cassandra.pelops.Pelops;

import org.scale7.cassandra.pelops.Selector;

public class PelopsClient {

public static void main(String[] args) {

Cluster cluster = new Cluster("192.168.11.124", 9160);

Pelops.addPool("Main", cluster, "LiftDNA_DB");

Mutator mutator = Pelops.createMutator("Main");

Column newColumn = mutator.newColumn("age", "30");

mutator.writeColumn("LiftDNA_Table", "shenbin", newColumn);

mutator.execute(ConsistencyLevel.ONE);

Selector selector = Pelops.createSelector("Main");

Column column = selector.getColumnFromRow("LiftDNA_Table", "shenbin", "age", ConsistencyLevel.ONE);

System.out.println(new String(column.getValue()));

mutator.deleteColumn("LiftDNA_Table", "shenbin", "age");

mutator.execute(ConsistencyLevel.ONE);

}

}需要用到的lib有:

apache-cassandra-thrift-1.0.6.jar

commons-pool-1.5.7.jar

guava-r09.jar

libthrift-0.6.1.jar

slf4j-api-1.6.1.jar

uuid-3.2.0.jar

此外,当然还少不了pelops,可以在这里下载到它:https://github.com/s7(scale7-core + scale7-pelops)

其他语言:

另外,还有很多其他的第三方客户端实现,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot整合GeoMesa Cassandra是为了利用GeoMesa库的强大地理空间处理能力,与Cassandra NoSQL数据库结合,以便在Spring应用中方便地执行地理数据的CRUD操作。GeoMesa是一个高度可扩展的开源框架,它抽象了底层的数据存储,使得开发者能够更专注于业务逻辑。 以下是整合步骤: 1. 添加依赖: 在你的`pom.xml`文件中添加GeoMesa和Spring Data Cassandra的依赖: ```xml <dependency> <groupId>org.locationtech.geomesa</groupId> <artifactId>geomesa-spring-boot-starter-cassandra</artifactId> <version>XX.YY.ZZ</version> <!-- 用最新版本替换 --> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-cassandra</artifactId> </dependency> ``` 记得替换版本号为最新的稳定版。 2. 配置GeoMesa Cassandra:在`application.properties`或`application.yml`中配置Cassandra连接信息,包括主机、端口、用户名、密码等。 3. 创建数据源:在Spring Boot应用中,使用Spring Data Cassandra的Repository接口来定义地理空间数据源。例如,假设你有一个`Feature`实体映射到GeoMesa中的一个表,你可以创建一个类似这样的Repository接口: ```java public interface FeatureRepository extends GeoMesaFeatureDao<Feature, UUID> { // CRUD operations List<Feature> findByBbox(BoundingBox bbox); Feature findById(UUID id); void save(Feature feature); void deleteById(UUID id); } ``` 4. 使用Repository:注入`FeatureRepository`并进行CRUD操作: ```java @Autowired private FeatureRepository featureRepository; public void createFeature(Feature feature) { featureRepository.save(feature); } public Feature getFeatureById(UUID id) { return featureRepository.findById(id); } public void updateFeature(Feature updatedFeature) { featureRepository.save(updatedFeature); } public void deleteFeature(UUID id) { featureRepository.deleteById(id); } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值