My internship needs me get familiar with cassandra. I downloaded astyanax cassandra from: https://github.com/Netflix/astyanax
After building astyanax from source via the commands: git clone git@github.com:Netflix/astyanax.git cd astyanax ./gradlew build
I created a new java project and copy+paste the sample code from here: https://github.com/Netflix/astyanax/blob/master/astyanax-examples/src/main/java/com/netflix/astyanax/examples/AstCQLClient.java
Now the problems arose. I did fix the path configuration, which is importing all .jar files generated from the gradlew build. But one (long)line of code is highlighted by red dash:
context = new AstyanaxContext.Builder()
.forCluster("Test Cluster")
.forKeyspace("test1")
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setPort(9160)
.setMaxConnsPerHost(1)
.setSeeds("127.0.0.1:9160")
)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setCqlVersion("3.0.0")
.setTargetCassandraVersion("1.2"))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
The warning message is: The type org.apache.cassandra.thrift.Cassandra$Client cannot be resolved. It is indirectly referenced from required .class files
I need experts help. Thanks a lot!!!
Sounds like you are missing the thrift dependency (thrift jar file). Either that or you are using an incompatible version of thrift. The simple solution is to use Maven and add the Astyanax dependency to your project. The more complex solution is to verify that that version of thrift you are import is compatible with the version of Astyanax being used.
Maven dependency (add this to your pom file):
<dependency>
<groupId>com.netflix.astyanax</groupId>
<artifactId>astyanax</artifactId>
<version>1.56.42</version>
</dependency>
You can work out a compatible version of Thrift for your Astyanax client using Astyanax's wiki. But knowing you built the project from Github, you want the latest thrift that is compatible with Cassandra, so you are after Thrift 9.0+ (for example libthrift-0.9.0.jar
).