简体   繁体   English

如何使用Datastax Java驱动程序在属性文件中提供Cassandra的连接详细信息

[英]How to give connection details for cassandra in properties file using datastax java driver

Initializer myInitializer = ... // your implementation
Cluster cluster = Cluster.buildFrom(myInitializer);

Im trying to connect to Cassandra cluster with several node details mentioning in addcontactpoints("192.1.1.1","192.2.2.2").build() . 我试图用在addcontactpoints("192.1.1.1","192.2.2.2").build()提到的几个节点详细信息连接到Cassandra集群。

Now I want to connect to Cassandra cluster with out mentioning the in that method. 现在,我想连接到Cassandra集群,而无需提及该方法。 I want to mention my node details in separate properties file and want to connect to my cluster using that properties file. 我想在单独的属性文件中提及我的节点详细信息,并希望使用该属性文件连接到集群。 I have got one method in Java driver called getcontactpoint() . 我在Java驱动程序中有一种方法叫做getcontactpoint()

I'm not getting how to use that and implement it. 我不知道如何使用它并实现它。 Please help me to improve my code 请帮助我改善代码

put all nodes ip like below nodes=192.1.1.1,192.2.2.2 将所有节点ip放在下面的节点= 192.1.1.1,192.2.2.2下

In java Resource interface is there by using that you can get your properties file 在Java Resource接口中,通过使用它可以获取属性文件

Like ResourceBundle resource=ResourceBundle.getBundle("cassandra") 像ResourceBundle resource = ResourceBundle.getBundle(“ cassandra”)

then by getProperty method you can get nodes and split it by comma(,) so it will gives you Array of String mean all IP . 然后通过getProperty方法,您可以获取节点并用comma(,)对其进行拆分,因此它将为您提供String Array,意味着所有IP。 Like nodes=resource.getString("nodes") 像nodes = resource.getString(“ nodes”)

then in method addContactPoints() just give nodes variable . 然后在方法addContactPoints()中只给节点变量。

Like addContactPoints(nodes) 像addContactPoints(nodes)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用datastax java驱动程序有效地使用批量写入cassandra? - How to efficiently use Batch writes to cassandra using datastax java driver? 如何使用带有Datastax Java驱动程序的CQL向Cassandra添加任意列? - How to add arbitrary columns to Cassandra using CQL with Datastax Java driver? 如何在Cassandra中使用datastax java驱动程序有效地使用准备好的语句? - How to use prepared statement efficiently using datastax java driver in Cassandra? Cassandra Datastax驱动程序 - 连接池 - Cassandra Datastax Driver - Connection Pool 无法使用Cassandra Datastax Java驱动程序连接到Cassandra节点之一 - Unable to connect to one of the Cassandra nodes using Cassandra Datastax Java Driver 告诉Datastax Java Cassandra驱动程序超时集群连接 - Tell Datastax Java Cassandra driver to timeout cluster connection Datastax Java Cassandra驱动程序:使用WHERE的多个AND语句? - Datastax Java Cassandra Driver: Multiple AND statements using WHERE? Cassandra:使用 DataStax Java 驱动程序选择一系列 TimeUUID - Cassandra: Selecting a Range of TimeUUIDs using the DataStax Java Driver 使用DataStax Java驱动程序1.0.4使用CQL连接到Cassandra时出现异常 - Exception when connecting to Cassandra with CQL using DataStax Java driver 1.0.4 我应该如何使用java的datastax cassandra驱动程序检查resultset是空还是null - How should I check if resultset is empty or null using datastax cassandra driver for java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM