Class KinesisProxy

  • All Implemented Interfaces:
    KinesisProxyInterface
    Direct Known Subclasses:
    DynamoDBStreamsProxy

    @Internal
    public class KinesisProxy
    extends Object
    implements KinesisProxyInterface
    Kinesis proxy implementation - a utility class that is used as a proxy to make calls to AWS Kinesis for several functions, such as getting a list of shards and fetching a batch of data records starting from a specified record sequence number.

    NOTE: In the AWS KCL library, there is a similar implementation - KinesisProxy. This implementation differs mainly in that we can make operations to arbitrary Kinesis streams, which is a needed functionality for the Flink Kinesis Connector since the consumer may simultaneously read from multiple Kinesis streams.

    • Constructor Detail

      • KinesisProxy

        protected KinesisProxy​(Properties configProps)
        Create a new KinesisProxy based on the supplied configuration properties.
        Parameters:
        configProps - configuration properties containing AWS credential and AWS region info
    • Method Detail

      • createKinesisClient

        protected com.amazonaws.services.kinesis.AmazonKinesis createKinesisClient​(Properties configProps)
        Create the Kinesis client, using the provided configuration properties and default ClientConfiguration. Derived classes can override this method to customize the client configuration.
      • create

        public static KinesisProxyInterface create​(Properties configProps)
        Creates a Kinesis proxy.
        Parameters:
        configProps - configuration properties
        Returns:
        the created kinesis proxy
      • getRecords

        public com.amazonaws.services.kinesis.model.GetRecordsResult getRecords​(String shardIterator,
                                                                                int maxRecordsToGet)
                                                                         throws InterruptedException
        Description copied from interface: KinesisProxyInterface
        Get the next batch of data records using a specific shard iterator.
        Specified by:
        getRecords in interface KinesisProxyInterface
        Parameters:
        shardIterator - a shard iterator that encodes info about which shard to read and where to start reading
        maxRecordsToGet - the maximum amount of records to retrieve for this batch
        Returns:
        the batch of retrieved records, also with a shard iterator that can be used to get the next batch
        Throws:
        InterruptedException - this method will retry with backoff if AWS Kinesis complains that the operation has exceeded the rate limit; this exception will be thrown if the backoff is interrupted.
      • getShardList

        public GetShardListResult getShardList​(Map<String,​String> streamNamesWithLastSeenShardIds)
                                        throws InterruptedException
        Description copied from interface: KinesisProxyInterface
        Get shard list of multiple Kinesis streams, ignoring the shards of each stream before a specified last seen shard id.
        Specified by:
        getShardList in interface KinesisProxyInterface
        Parameters:
        streamNamesWithLastSeenShardIds - a map with stream as key, and last seen shard id as value
        Returns:
        result of the shard list query
        Throws:
        InterruptedException - this method will retry with backoff if AWS Kinesis complains that the operation has exceeded the rate limit; this exception will be thrown if the backoff is interrupted.
      • getShardIterator

        public String getShardIterator​(StreamShardHandle shard,
                                       String shardIteratorType,
                                       @Nullable
                                       Object startingMarker)
                                throws InterruptedException
        Description copied from interface: KinesisProxyInterface
        Get a shard iterator from the specified position in a shard. The retrieved shard iterator can be used in KinesisProxyInterface.getRecords(String, int)} to read data from the Kinesis shard.
        Specified by:
        getShardIterator in interface KinesisProxyInterface
        Parameters:
        shard - the shard to get the iterator
        shardIteratorType - the iterator type, defining how the shard is to be iterated (one of: TRIM_HORIZON, LATEST, AT_TIMESTAMP, AT_SEQUENCE_NUMBER, AFTER_SEQUENCE_NUMBER)
        startingMarker - should be null if shardIteratorType is TRIM_HORIZON or LATEST, should be a Date value if shardIteratorType is AT_TIMESTAMP, should be a String representing the sequence number if shardIteratorType is AT_SEQUENCE_NUMBER, AFTER_SEQUENCE_NUMBER
        Returns:
        shard iterator which can be used to read data from Kinesis
        Throws:
        InterruptedException - this method will retry with backoff if AWS Kinesis complains that the operation has exceeded the rate limit; this exception will be thrown if the backoff is interrupted.
      • isRecoverableSdkClientException

        protected boolean isRecoverableSdkClientException​(com.amazonaws.SdkClientException ex)
        Determines whether the exception is recoverable using exponential-backoff.
        Parameters:
        ex - Exception to inspect
        Returns:
        true if the exception can be recovered from, else false
      • isRecoverableException

        protected static boolean isRecoverableException​(com.amazonaws.AmazonServiceException ex)
        Determines whether the exception is recoverable using exponential-backoff.
        Parameters:
        ex - Exception to inspect
        Returns:
        true if the exception can be recovered from, else false
      • describeStream

        protected com.amazonaws.services.kinesis.model.DescribeStreamResult describeStream​(String streamName,
                                                                                           @Nullable
                                                                                           String startShardId)
                                                                                    throws InterruptedException
        Get metainfo for a Kinesis stream, which contains information about which shards this Kinesis stream possess.

        This method is using a "full jitter" approach described in AWS's article, "Exponential Backoff and Jitter". This is necessary because concurrent calls will be made by all parallel subtask's fetcher. This jitter backoff approach will help distribute calls across the fetchers over time.

        Parameters:
        streamName - the stream to describe
        startShardId - which shard to start with for this describe operation
        Returns:
        the result of the describe stream operation
        Throws:
        InterruptedException