Kinesis consumer application in c++



My kinesis stream consumer is written in Java and I would like to move it to c++ since my application is latency sensitive. I am looking for a example code on how to get started, but despite multiple hrs of search no luck. At the moment I am using two applications , one written in Java for consuming the stream and stream data is sent over raw socket to other application written in C++. I would like to implement everything in c++ if possible. I found that the KCL examples contains consumer applications for Java and Python only. If there is any C++ example then it will definitely help.

Thanks in advance.

已提問 1 年前檢視次數 456 次
1 個回答


One of the approaches to create an Amazon Kinesis Consumer for C++ is to use the AWS SDK for C++. The SDK provides API's that you can use to create a consumer application for C++.

High level steps below,

  1. Get AWS SDK for C++ on your work environment. You can download it from here:
  2. Create an Amazon Kinesis stream using the AWS Management Console or the AWS SDK for C++.
  3. Create a Kinesis client object in your C++ application using the SDK API.
  4. Use the client object to read data from the Kinesis stream using the GetRecords API. You can use the ShardIteratorType parameter to specify the position in the shard from which to start reading data.
  5. Process the data received from the Kinesis stream in your C++ application.

A code sample is below, please customise it based on your requirements,

#include <aws/kinesis/KinesisClient.h>
#include <aws/core/utils/Outcome.h>
#include <aws/core/utils/logging/LogLevel.h>

using namespace Aws::Kinesis;
using namespace Aws::Utils::Logging;
using namespace Aws::Client;
using namespace Aws::Utils;

int main(int argc, char** argv)
    // Initialize the AWS SDK for C++
    Aws::SDKOptions options;

    // Set up the Kinesis client
    ClientConfiguration clientConfig;
    KinesisClient kinesis(clientConfig);

    // Set up the request to read data from the Kinesis stream
    GetRecordsRequest request;

    // Read data from the Kinesis stream
    while (true)
        GetRecordsOutcome outcome = kinesis.GetRecords(request);
        if (outcome.IsSuccess())
            std::vector<Record> records = outcome.GetResult().GetRecords();
            for (const auto& record : records)
                // Process the record data
                std::cout << record.GetData() << std::endl;

            // Set the shard iterator to the next position
            // Handle the error
            std::cout << "Error reading data from Kinesis stream: " << outcome.GetError().GetMessage() << std::endl;

    // Shutdown the AWS SDK for C++

    return 0;
已回答 1 年前

您尚未登入。 登入 去張貼答案。