| 1 | Driver Core |
| 2 | =========== |
| 3 | |
| 4 | This is the core module of the DataStax Java Driver for Apache Cassandra (C*), |
| 5 | which offers a simple (as in, not abstracted) but complete API to work with |
| 6 | CQL3. The main goal of the module is to handle all the functionality related |
| 7 | to managing connections to a Cassandra cluster (but leaving higher level |
| 8 | abstraction like object mapping to separate modules). |
| 9 | |
| 10 | |
| 11 | Features |
| 12 | -------- |
| 13 | |
| 14 | The features provided by the core module includes: |
| 15 | - Asynchronous: the driver uses the new CQL binary protocol asynchronous |
| 16 | capabilities. Only a relatively low number of connections per nodes needs to |
| 17 | be maintained open to achieve good performance. |
| 18 | - Nodes discovery: the driver automatically discovers and uses all nodes of the |
| 19 | C* cluster, including newly bootstrapped ones. |
| 20 | - Configurable load balancing: the driver allows for custom routing and load |
| 21 | balancing of queries to C* nodes. Out of the box, round robin is provided |
| 22 | with optional data-center awareness (only nodes from the local data-center |
| 23 | are queried (and have connections maintained to)) and optional token |
| 24 | awareness (that is, the ability to prefer a replica for the query as coordinator). |
| 25 | - Transparent fail-over: if C* nodes fail or become unreachable, the driver |
| 26 | automatically and transparently tries other nodes and schedules |
| 27 | reconnection to the dead nodes in the background. |
| 28 | - C* trace handling: tracing can be set on a per-query basis and the driver |
| 29 | provides a convenient API to retrieve the trace. |
| 30 | - Convenient schema access: the driver exposes a C* schema in a usable way. |
| 31 | - Configurable retry policy: a retry policy can be set to define a precise |
| 32 | behavior to adopt on query execution exceptions (for example, timeouts, |
| 33 | unavailability). This avoids polluting client code with retry-related code. |
| 34 | |
| 35 | |
| 36 | Prerequisite |
| 37 | ------------ |
| 38 | |
| 39 | The driver uses the binary protocol that was introduced in Cassandra 1.2. |
| 40 | It only works with a version of Cassandra greater than or equal to 1.2. |
| 41 | The beta2 1.2 works with the driver, but not the beta1 1.2 release. |
| 42 | Furthermore, the binary protocol server is not started with the default |
| 43 | configuration file in Cassandra 1.2. You must edit the cassandra.yaml file: |
| 44 | |
| 45 | start_native_transport: true |
| 46 | |
| 47 | If you want to run the (currently few) unit tests provided with this driver, |
| 48 | you will also need to have ccm installed (http://github.com/pcmanus/ccm) as the |
| 49 | tests use it. Also note that the first time you run the tests, ccm will |
| 50 | download/compile the source of C* under the hood, which may require some time |
| 51 | (that depends on your Internet connection or machine). |
| 52 | |
| 53 | If you are having issues connecting to the cluster (seeing ``NoHostAvailableConnection`` exceptions) please check the |
| 54 | `connection requirements <https://github.com/datastax/java-driver/wiki/Connection-requirements>`_. |
| 55 | |
| 56 | Installing |
| 57 | ---------- |
| 58 | |
| 59 | The last release of the driver is available on Maven Central. You can install |
| 60 | it in your application using the following Maven dependency:: |
| 61 | |
| 62 | <dependency> |
| 63 | <groupId>com.datastax.cassandra</groupId> |
| 64 | <artifactId>cassandra-driver-core</artifactId> |
| 65 | <version>1.0.6</version> |
| 66 | </dependency> |
| 67 | |
| 68 | **DSE users** should use the following Maven dependency (*note the version is set to 1.0.5-dse*):: |
| 69 | |
| 70 | <dependency> |
| 71 | <groupId>com.datastax.cassandra</groupId> |
| 72 | <artifactId>cassandra-driver-core</artifactId> |
| 73 | <version>1.0.5-dse</version> |
| 74 | </dependency> |
| 75 | |
| 76 | **Cassandra 2.0.x users** should consider the following Maven dependency:: |
| 77 | |
| 78 | <dependency> |
| 79 | <groupId>com.datastax.cassandra</groupId> |
| 80 | <artifactId>cassandra-driver-core</artifactId> |
| 81 | <version>2.0.0</version> |
| 82 | </dependency> |
| 83 | |
| 84 | |
| 85 | Getting Started |
| 86 | --------------- |
| 87 | |
| 88 | Suppose you have a Cassandra cluster running on 3 nodes whose hostnames are: |
| 89 | cass1, cass2 and cass3. A simple example using this core driver could be:: |
| 90 | |
| 91 | Cluster cluster = Cluster.builder() |
| 92 | .addContactPoints("cass1", "cass2") |
| 93 | .build(); |
| 94 | Session session = cluster.connect("db1"); |
| 95 | |
| 96 | for (Row row : session.execute("SELECT * FROM table1")) |
| 97 | // do something ... |
| 98 | |
| 99 | Please note that when we build the Cluster object, we only provide the address |
| 100 | to 2 Cassandra hosts. We could have provided only one host or the 3 of them, |
| 101 | this doesn't matter as long as the driver is able to contact one of the host |
| 102 | provided as "contact points". Even if only one host was provided, the driver |
| 103 | would use this host to discover the other ones and use the whole cluster |
| 104 | automatically. This is also true for new nodes joining the cluster. |
| 105 | |
| 106 | For now, please refer to the API reference (http://www.datastax.com/drivers/java/apidocs/). |
| 107 | More informations and documentation will come later. |