Search in sources :

Example 6 with AmazonKinesisClient

use of com.amazonaws.services.kinesis.AmazonKinesisClient in project beam by apache.

the class KinesisUploader method uploadAll.

public static void uploadAll(List<String> data, KinesisTestOptions options) {
    AmazonKinesisClient client = new AmazonKinesisClient(new StaticCredentialsProvider(new BasicAWSCredentials(options.getAwsAccessKey(), options.getAwsSecretKey()))).withRegion(Regions.fromName(options.getAwsKinesisRegion()));
    List<List<String>> partitions = Lists.partition(data, MAX_NUMBER_OF_RECORDS_IN_BATCH);
    for (List<String> partition : partitions) {
        List<PutRecordsRequestEntry> allRecords = newArrayList();
        for (String row : partition) {
            allRecords.add(new PutRecordsRequestEntry().withData(ByteBuffer.wrap(row.getBytes(Charsets.UTF_8))).withPartitionKey(Integer.toString(row.hashCode())));
        }
        PutRecordsResult result;
        do {
            result = client.putRecords(new PutRecordsRequest().withStreamName(options.getAwsKinesisStream()).withRecords(allRecords));
            List<PutRecordsRequestEntry> failedRecords = newArrayList();
            int i = 0;
            for (PutRecordsResultEntry row : result.getRecords()) {
                if (row.getErrorCode() != null) {
                    failedRecords.add(allRecords.get(i));
                }
                ++i;
            }
            allRecords = failedRecords;
        } while (result.getFailedRecordCount() > 0);
    }
}
Also used : AmazonKinesisClient(com.amazonaws.services.kinesis.AmazonKinesisClient) PutRecordsRequestEntry(com.amazonaws.services.kinesis.model.PutRecordsRequestEntry) StaticCredentialsProvider(com.amazonaws.internal.StaticCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) PutRecordsResult(com.amazonaws.services.kinesis.model.PutRecordsResult) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) PutRecordsResultEntry(com.amazonaws.services.kinesis.model.PutRecordsResultEntry) PutRecordsRequest(com.amazonaws.services.kinesis.model.PutRecordsRequest)

Aggregations

AmazonKinesisClient (com.amazonaws.services.kinesis.AmazonKinesisClient)6 DescribeStreamResult (com.amazonaws.services.kinesis.model.DescribeStreamResult)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)2 PutRecordsRequest (com.amazonaws.services.kinesis.model.PutRecordsRequest)2 PutRecordsRequestEntry (com.amazonaws.services.kinesis.model.PutRecordsRequestEntry)2 PutRecordsResult (com.amazonaws.services.kinesis.model.PutRecordsResult)2 Properties (java.util.Properties)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ParameterTool (org.apache.flink.api.java.utils.ParameterTool)2 Configuration (org.apache.flink.configuration.Configuration)2 LocalFlinkMiniCluster (org.apache.flink.runtime.minicluster.LocalFlinkMiniCluster)2 ExactlyOnceValidatingConsumerThread (org.apache.flink.streaming.connectors.kinesis.testutils.ExactlyOnceValidatingConsumerThread)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 ClientConfigurationFactory (com.amazonaws.ClientConfigurationFactory)1 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 StaticCredentialsProvider (com.amazonaws.internal.StaticCredentialsProvider)1 Region (com.amazonaws.regions.Region)1 AmazonKinesis (com.amazonaws.services.kinesis.AmazonKinesis)1 LimitExceededException (com.amazonaws.services.kinesis.model.LimitExceededException)1 PutRecordsResultEntry (com.amazonaws.services.kinesis.model.PutRecordsResultEntry)1