Search in sources :

Example 1 with AmazonDynamoDBStreamsAdapterClient

use of com.amazonaws.services.dynamodbv2.streamsadapter.AmazonDynamoDBStreamsAdapterClient in project flink by apache.

the class DynamoDBStreamsProxy method createKinesisClient.

/**
 * Creates an AmazonDynamoDBStreamsAdapterClient. Uses it as the internal client interacting
 * with the DynamoDB streams.
 *
 * @param configProps configuration properties
 * @return an AWS DynamoDB streams adapter client
 */
@Override
protected AmazonKinesis createKinesisClient(Properties configProps) {
    ClientConfiguration awsClientConfig = new ClientConfigurationFactory().getConfig();
    setAwsClientConfigProperties(awsClientConfig, configProps);
    AWSCredentialsProvider credentials = getCredentialsProvider(configProps);
    awsClientConfig.setUserAgentPrefix(String.format(USER_AGENT_FORMAT, EnvironmentInformation.getVersion(), EnvironmentInformation.getRevisionInformation().commitId));
    AmazonDynamoDBStreamsAdapterClient adapterClient = new AmazonDynamoDBStreamsAdapterClient(credentials, awsClientConfig);
    if (configProps.containsKey(AWS_ENDPOINT)) {
        adapterClient.setEndpoint(configProps.getProperty(AWS_ENDPOINT));
    } else {
        adapterClient.setRegion(Region.getRegion(Regions.fromName(configProps.getProperty(AWS_REGION))));
    }
    return adapterClient;
}
Also used : AmazonDynamoDBStreamsAdapterClient(com.amazonaws.services.dynamodbv2.streamsadapter.AmazonDynamoDBStreamsAdapterClient) ClientConfigurationFactory(com.amazonaws.ClientConfigurationFactory) ClientConfiguration(com.amazonaws.ClientConfiguration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 2 with AmazonDynamoDBStreamsAdapterClient

use of com.amazonaws.services.dynamodbv2.streamsadapter.AmazonDynamoDBStreamsAdapterClient in project aws-doc-sdk-examples by awsdocs.

the class StreamsAdapterDemo method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    System.out.println("Starting demo...");
    dynamoDBClient = AmazonDynamoDBClientBuilder.standard().withRegion(awsRegion).build();
    cloudWatchClient = AmazonCloudWatchClientBuilder.standard().withRegion(awsRegion).build();
    dynamoDBStreamsClient = AmazonDynamoDBStreamsClientBuilder.standard().withRegion(awsRegion).build();
    adapterClient = new AmazonDynamoDBStreamsAdapterClient(dynamoDBStreamsClient);
    String srcTable = tablePrefix + "-src";
    String destTable = tablePrefix + "-dest";
    recordProcessorFactory = new StreamsRecordProcessorFactory(dynamoDBClient, destTable);
    setUpTables();
    workerConfig = new KinesisClientLibConfiguration("streams-adapter-demo", streamArn, awsCredentialsProvider, "streams-demo-worker").withMaxRecords(1000).withIdleTimeBetweenReadsInMillis(500).withInitialPositionInStream(InitialPositionInStream.TRIM_HORIZON);
    System.out.println("Creating worker for stream: " + streamArn);
    worker = StreamsWorkerFactory.createDynamoDbStreamsWorker(recordProcessorFactory, workerConfig, adapterClient, dynamoDBClient, cloudWatchClient);
    System.out.println("Starting worker...");
    Thread t = new Thread(worker);
    t.start();
    Thread.sleep(25000);
    worker.shutdown();
    t.join();
    if (StreamsAdapterDemoHelper.scanTable(dynamoDBClient, srcTable).getItems().equals(StreamsAdapterDemoHelper.scanTable(dynamoDBClient, destTable).getItems())) {
        System.out.println("Scan result is equal.");
    } else {
        System.out.println("Tables are different!");
    }
    System.out.println("Done.");
    cleanupAndExit(0);
}
Also used : AmazonDynamoDBStreamsAdapterClient(com.amazonaws.services.dynamodbv2.streamsadapter.AmazonDynamoDBStreamsAdapterClient) KinesisClientLibConfiguration(com.amazonaws.services.kinesis.clientlibrary.lib.worker.KinesisClientLibConfiguration)

Aggregations

AmazonDynamoDBStreamsAdapterClient (com.amazonaws.services.dynamodbv2.streamsadapter.AmazonDynamoDBStreamsAdapterClient)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 ClientConfigurationFactory (com.amazonaws.ClientConfigurationFactory)1 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 KinesisClientLibConfiguration (com.amazonaws.services.kinesis.clientlibrary.lib.worker.KinesisClientLibConfiguration)1