Skip to content

Commit 1b55f24

Browse files
authored
CPP-816 - Add quickstart guide for Constellation (#296)
* CPP-816 - Add quickstart guide for Constellation
1 parent 3e617e7 commit 1b55f24

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

cpp-driver/topics/cloud/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Cloud
2+
3+
## Connecting to your [DataStax Apollo database on Constellation] using a secure connection bundle
4+
5+
**Note:** Both the C++ Driver for Apache Cassandra and the C++ Driver for DataStax
6+
Enterprise (DSE) use the same code to connect and query your Cassandra database,
7+
but when using the DSE driver use the header `#include <dse.h>`.
8+
9+
Use the following code snippet to connect your database:
10+
11+
```c
12+
#include <cassandra.h> /* Use "#include <dse.h>" when using the C++ DSE Driver */
13+
#include <stdio.h>
14+
15+
int main(int argc, char* argv[]) {
16+
/* Setup and connect to cluster */
17+
CassCluster* cluster = cass_cluster_new();
18+
CassSession* session = cass_session_new();
19+
20+
/* Setup driver to connect to the cloud using the secure connection bundle */
21+
const char* secure_connect_bundle = "/path/to/secure-connect-database_name.zip";
22+
if (cass_cluster_set_cloud_secure_connection_bundle(cluster, secure_connect_bundle) != CASS_OK) {
23+
fprintf(stderr, "Unable to configure cloud using the secure connection bundle: %s\n",
24+
secure_connect_bundle);
25+
return 1;
26+
}
27+
28+
/* Set credentials provided when creating your database */
29+
cass_cluster_set_credentials(cluster, "username", "password");
30+
31+
CassFuture* connect_future = cass_session_connect(session, cluster);
32+
33+
if (cass_future_error_code(connect_future) == CASS_OK) {
34+
/* Use the session to run queries */
35+
} else {
36+
/* Handle error */
37+
}
38+
39+
cass_future_free(connect_future);
40+
cass_cluster_free(cluster);
41+
cass_session_free(session);
42+
43+
return 0;
44+
}
45+
```
46+
47+
**Note:** `cass_cluster_set_contact_points()` and `cass_cluster_set_ssl()` should not used
48+
in conjunction with `cass_cluster_set_cloud_secure_connection_bundle()`.
49+
50+
[DataStax Apollo database on Constellation]: https://constellation.datastax.com/

0 commit comments

Comments
 (0)