Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

10/31/2017

Reading time:4 min

DataStax C++ Driver

by John Doe

A modern, feature-rich, and highly tunable C/C++ client library forApache Cassandra (1.2+) and DataStax Enterprise (3.1+) using exclusivelyCassandra's native protocol and Cassandra Query Language v3.Code: https://github.com/datastax/cpp-driverBinaries: http://downloads.datastax.com/cpp-driver/Docs: http://datastax.github.io/cpp-driverJIRA: https://datastax-oss.atlassian.net/browse/CPPMailing List: https://groups.google.com/a/lists.datastax.com/forum/#!forum/cpp-driver-userIRC: #datastax-drivers on irc.freenode.net <http://freenode.net>Note: DataStax products do not support big-endian systems.What's New in 2.5/2.6Support for durationSpeculative executionIdempotent statementsSSL can be enabled without re-initializing the underlying library (e.g. OpenSSL)More information about features included in 2.3 can be found in this blogpost.Upgrading from 2.0 or 2.1 to 2.2+The new schema metadata API in 2.2 required some breaking API changes.Applications that used the previous schema metadata API from 2.0 and 2.1 willrequire some small modifications to use the new API. More information about thenew schema metadata API can be found in thisblog post.Upgrading from 1.0 to 2.0+There were a couple breaking API changes between 1.0 and 2.0 that are documentedhere.FeaturesAsynchronous APISimple, Prepared, and Batch statementsAsynchronous I/O, parallel execution, and request pipeliningConnection poolingAutomatic node discoveryAutomatic reconnectionConfigurable load balancingWorks with any cluster sizeAuthenticationSSLLatency-aware routingPerformance metricsTuples and UDTsNested collectionsRetry policiesClient-side timestampsData typesIdle connection heartbeatsSupport for materialized view and secondary index metadataSupport for clustering key order, frozen<> and Cassandra version metadataBlacklist, whitelist DC, and blacklist DC load balancing policiesCustom authenticatorsReverse DNS with SSL peer identity verification supportRandomized contact pointsCompatibilityThis release is compatible with Apache Cassandra 1.2, 2.0, 2.1, 2.2 and 3.0.A complete compatibility matrix for both Apache Cassandra and DataStaxEnterprise can be foundhere.InstallationBinary packages are available forCentOS, Ubuntu and Windows. Packages for the driver's dependencies, libuv (1.x)and OpenSSL, are also provided under the dependencies directory for eachplatform e.g. CentOS 7,Ubuntu 14.04,Windows.Note: CentOS and Ubuntu use the version of OpenSSL provided with thedistribution.The driver can also be built fromsource.Feedback RequestedHelp us focus our efforts! Provide your input on the C/C++ Driver Platform and Runtime Survey (we kept it short).ExamplesThere are several examples provided here: examples.A Simple Example#include <cassandra.h>#include <stdio.h>int main(int argc, char* argv[]) { /* Setup and connect to cluster */ CassFuture* connect_future = NULL; CassCluster* cluster = cass_cluster_new(); CassSession* session = cass_session_new(); char* hosts = "127.0.0.1"; if (argc > 1) { hosts = argv[1]; } /* Add contact points */ cass_cluster_set_contact_points(cluster, hosts); /* Provide the cluster object as configuration to connect the session */ connect_future = cass_session_connect(session, cluster); if (cass_future_error_code(connect_future) == CASS_OK) { CassFuture* close_future = NULL; /* Build statement and execute query */ const char* query = "SELECT release_version FROM system.local"; CassStatement* statement = cass_statement_new(query, 0); CassFuture* result_future = cass_session_execute(session, statement); if (cass_future_error_code(result_future) == CASS_OK) { /* Retrieve result set and get the first row */ const CassResult* result = cass_future_get_result(result_future); const CassRow* row = cass_result_first_row(result); if (row) { const CassValue* value = cass_row_get_column_by_name(row, "release_version"); const char* release_version; size_t release_version_length; cass_value_get_string(value, &release_version, &release_version_length); printf("release_version: '%.*s'\n", (int)release_version_length, release_version); } cass_result_free(result); } else { /* Handle error */ const char* message; size_t message_length; cass_future_error_message(result_future, &message, &message_length); fprintf(stderr, "Unable to run query: '%.*s'\n", (int)message_length, message); } cass_statement_free(statement); cass_future_free(result_future); /* Close the session */ close_future = cass_session_close(session); cass_future_wait(close_future); cass_future_free(close_future); } else { /* Handle error */ const char* message; size_t message_length; cass_future_error_message(connect_future, &message, &message_length); fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length, message); } cass_future_free(connect_future); cass_cluster_free(cluster); cass_session_free(session); return 0;}LicenseCopyright (c) 2014-2016 DataStaxLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

Illustration Image

Build Status: Linux Build Status: Windows

A modern, feature-rich, and highly tunable C/C++ client library for Apache Cassandra (1.2+) and DataStax Enterprise (3.1+) using exclusively Cassandra's native protocol and Cassandra Query Language v3.

Note: DataStax products do not support big-endian systems.

What's New in 2.5/2.6

More information about features included in 2.3 can be found in this blog post.

Upgrading from 2.0 or 2.1 to 2.2+

The new schema metadata API in 2.2 required some breaking API changes. Applications that used the previous schema metadata API from 2.0 and 2.1 will require some small modifications to use the new API. More information about the new schema metadata API can be found in this blog post.

Upgrading from 1.0 to 2.0+

There were a couple breaking API changes between 1.0 and 2.0 that are documented here.

Features

Compatibility

This release is compatible with Apache Cassandra 1.2, 2.0, 2.1, 2.2 and 3.0.

A complete compatibility matrix for both Apache Cassandra and DataStax Enterprise can be found here.

Installation

Binary packages are available for CentOS, Ubuntu and Windows. Packages for the driver's dependencies, libuv (1.x) and OpenSSL, are also provided under the dependencies directory for each platform e.g. CentOS 7, Ubuntu 14.04, Windows.

Note: CentOS and Ubuntu use the version of OpenSSL provided with the distribution.

The driver can also be built from source.

Feedback Requested

Help us focus our efforts! Provide your input on the C/C++ Driver Platform and Runtime Survey (we kept it short).

Examples

There are several examples provided here: examples.

A Simple Example

#include <cassandra.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
  /* Setup and connect to cluster */
  CassFuture* connect_future = NULL;
  CassCluster* cluster = cass_cluster_new();
  CassSession* session = cass_session_new();
  char* hosts = "127.0.0.1";
  if (argc > 1) {
    hosts = argv[1];
  }
  /* Add contact points */
  cass_cluster_set_contact_points(cluster, hosts);
  /* Provide the cluster object as configuration to connect the session */
  connect_future = cass_session_connect(session, cluster);
  if (cass_future_error_code(connect_future) == CASS_OK) {
    CassFuture* close_future = NULL;
    /* Build statement and execute query */
    const char* query = "SELECT release_version FROM system.local";
    CassStatement* statement = cass_statement_new(query, 0);
    CassFuture* result_future = cass_session_execute(session, statement);
    if (cass_future_error_code(result_future) == CASS_OK) {
      /* Retrieve result set and get the first row */
      const CassResult* result = cass_future_get_result(result_future);
      const CassRow* row = cass_result_first_row(result);
      if (row) {
        const CassValue* value = cass_row_get_column_by_name(row, "release_version");
        const char* release_version;
        size_t release_version_length;
        cass_value_get_string(value, &release_version, &release_version_length);
        printf("release_version: '%.*s'\n", (int)release_version_length, release_version);
      }
      cass_result_free(result);
    } else {
      /* Handle error */
      const char* message;
      size_t message_length;
      cass_future_error_message(result_future, &message, &message_length);
      fprintf(stderr, "Unable to run query: '%.*s'\n", (int)message_length, message);
    }
    cass_statement_free(statement);
    cass_future_free(result_future);
    /* Close the session */
    close_future = cass_session_close(session);
    cass_future_wait(close_future);
    cass_future_free(close_future);
  } else {
    /* Handle error */
    const char* message;
    size_t message_length;
    cass_future_error_message(connect_future, &message, &message_length);
    fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length, message);
  }
  cass_future_free(connect_future);
  cass_cluster_free(cluster);
  cass_session_free(session);
  return 0;
}

License

Copyright (c) 2014-2016 DataStax

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Related Articles

packages
cassandra
admin-monitor

DataStax Enterprise OpsCenter

John Doe

7/24/2018

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

libraries