C++ SDK usage instructions

Updated at:

This topic describes the prerequisites and environment required to use the C++ SDK.

Prerequisites

The DataHub C++ SDK must be compiled with GCC 4.9.2. Before installation and use, make sure that the build environment meets this requirement.

Download the C++ SDK

Download links are available for the following versions:

Initialize the environment

Before accessing DataHub, prepare the AccessKey ID and AccessKey Secret of an Alibaba Cloud account and the endpoint of the DataHub service. For information about how to create an AccessKey pair, see Create an AccessKey pair.

The following example initializes DatahubClient by using the account credentials and the specified endpoint. Before use, replace the placeholders with actual values.

Before running the example, set the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET, and replace <Endpoint> with the DataHub endpoint. At the top of the source file, keep the existing DataHub C++ SDK header files and add the following standard library header files:

#include <cstdlib>
#include <iostream>
#include <string>

Add the following code to the main function:

const char* accessKeyId = std::getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
const char* accessKeySecret = std::getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");

if (accessKeyId == nullptr || *accessKeyId == '\0' ||
    accessKeySecret == nullptr || *accessKeySecret == '\0') {
    std::cerr << "Set ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.\n";
    return EXIT_FAILURE;
}

Account account;
account.id = accessKeyId;
account.key = accessKeySecret;

std::string projectName = "test_project";
std::string topicName = "test_cpp";
std::string comment = "test";

std::string endpoint = "<Endpoint>";
Configuration conf(account, endpoint);
DatahubClient client(conf);