Cassandra CQL driver implementation

时间:2015-05-24 21:44:26

标签: java cassandra cql drivers nosql

I have used Cassandra CQL driver to implement some module. I know CQL driver works on port 9042.My module is working fine on port 9042 for cassandra servers(tried both local and remote). However due to some constraints on the data center port 9042 is not open for Cassandra. I need to make my application work on this data center.

Can we use the same code in some way with port 9160? I know 9160 is the thrift port and used for many other drivers for Cassandra. I was just wondering if there is any hack possible to make CQL driver work on 9160 or modify the code as little as possible to make it work on 9160.

Currently when I try to use the same code with port 9160 it gives the following error

com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s)  tried for query failed (tried: xx.yy.zz.aa        (com.datastax.driver.core.ConnectionException:  [xx.yy.zz.aa :9160] Unexpected   error during   transport initialization 
(com.datastax.driver.core.ConnectionException:   [xx.yy.zz.aa :9160] Operation timed out)),         xx.yy.zz.aa :9160 

When I try to telnet 9160 port

telnet xx.yy.zz.aa 9160
Trying xx.yy.zz.aa...
Connected to xx.yy.zz.aa.
Escape character is '^]'.
xyzaaaa
Connection closed by foreign host.

Looking for some help.

1 个答案:

答案 0 :(得分:1)

You can make the CQL interface available on port 9160 by changing the native_transport_port from 9042 to 9160 in cassandra.yaml on your cassandra server(s). You will also need to change rpc_port to something other than 9160.

In the datastax java-driver you can configure the port to use in Cluster.Builder by using the withPort method.