connect to local cassandra nodes using datastax java driver?

你说的曾经没有我的故事 提交于 2019-12-02 06:35:11

By default the datastax drivers will only connect to nodes in the local DC. If you do not use withLocalDc it will attempt to discern the local datacenter from the DC of the contact point it is able to connect to.

If you want the driver to fail over to host in remote data center(s) you should use withUsedHostsPerRemoteDc, i.e.:

cluster.builder()        
  .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder()
    .withLocalDc("DC1")
    .withUsedHostsPerRemoteDc(3).build())

With this configuration, the driver will establish connections to 3 hosts in each remote DC, and only send queries to them if all hosts in the local datacenter is down.

There are other strategies for failover to remote data centers. For example, you could run your application clients in each same physical data center as your C* data centers, and then when a physical data center fails, you can fail over at a higher level (like your load balancer).

Also my pooling configuration options is right here which I am using in the above code?

I think what you have is fine. The defaults are fine too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!