[英]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.