zoukankan      html  css  js  c++  java
  • Cassandra--JAVA访问Cassandra数据

    JAVA创建Cluster对象

    cluster = Cluster.builder()
        .addContactPoints(contactPoints)
        .withRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE))
        .withSocketOptions(new SocketOptions().setKeepAlive(true).setReadTimeoutMillis(10000))
        .withAuthProvider(new PlainTextAuthProvider(cassandraUser, cassandraPwd))
        .withTimestampGenerator(new AtomicMonotonicTimestampGenerator())
        .withPoolingOptions(new PoolingOptions().setMaxConnectionsPerHost(HostDistance.LOCAL, 4))
        .build();

    相关知识点:

    针对数据库操作失败,Cassandra提供四种重试策略:
    1、DefaultRetryPolicy,没有查询到数据,或者写入时超时的情况下进行重新查询
    2、DowngradingConsistencyRetryPolicy,与DefaultRetryPolicy一样,不同点是考虑了最终数据一致性问题
    3、FallthroughRetryPolicy,不重试查询,但允许客户端业务逻辑实现重试
    4、LoggingRetryPolicy,不重试查询,用来记录日志信息,info级别
    
    
    针对数据节点连接失败,Casssandra提供两种重连策略:
    1、ConstantReconnectionPolicy,固定时间间隔进行重连
    2、ExponentialReconnectionPolicy,指数级别增加重连时间,但不会超过最大重连时间
    
    
    在创建Cluster时,无需将所有Cassandra节点信息录入到ContactPoints列表中,Cassandra驱动会自动从录入节点获取所有群集节点数据。
  • 相关阅读:
    求给定数里的数的质数最大——pku3048
    poj1106
    poj1450
    poj1094
    poj1111
    poj1120
    C#.NET学习笔记 类,接口,对象
    在Repeater中嵌套使用Repeater
    数据表分区解决方案(转)
    C#小数点格式化
  • 原文地址:https://www.cnblogs.com/gaogao67/p/10551787.html
Copyright © 2011-2022 走看看