Class KinesisProxy
- java.lang.Object
-
- org.apache.flink.streaming.connectors.kinesis.proxy.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 Summary
Constructors Modifier Constructor Description protectedKinesisProxy(Properties configProps)Create a new KinesisProxy based on the supplied configuration properties.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static KinesisProxyInterfacecreate(Properties configProps)Creates a Kinesis proxy.protected com.amazonaws.services.kinesis.AmazonKinesiscreateKinesisClient(Properties configProps)Create the Kinesis client, using the provided configuration properties and defaultClientConfiguration.protected com.amazonaws.services.kinesis.model.DescribeStreamResultdescribeStream(String streamName, String startShardId)Get metainfo for a Kinesis stream, which contains information about which shards this Kinesis stream possess.com.amazonaws.services.kinesis.model.GetRecordsResultgetRecords(String shardIterator, int maxRecordsToGet)Get the next batch of data records using a specific shard iterator.StringgetShardIterator(StreamShardHandle shard, String shardIteratorType, Object startingMarker)Get a shard iterator from the specified position in a shard.GetShardListResultgetShardList(Map<String,String> streamNamesWithLastSeenShardIds)Get shard list of multiple Kinesis streams, ignoring the shards of each stream before a specified last seen shard id.protected static booleanisRecoverableException(com.amazonaws.AmazonServiceException ex)Determines whether the exception is recoverable using exponential-backoff.protected booleanisRecoverableSdkClientException(com.amazonaws.SdkClientException ex)Determines whether the exception is recoverable using exponential-backoff.
-
-
-
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 defaultClientConfiguration. 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:KinesisProxyInterfaceGet the next batch of data records using a specific shard iterator.- Specified by:
getRecordsin interfaceKinesisProxyInterface- Parameters:
shardIterator- a shard iterator that encodes info about which shard to read and where to start readingmaxRecordsToGet- 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:KinesisProxyInterfaceGet shard list of multiple Kinesis streams, ignoring the shards of each stream before a specified last seen shard id.- Specified by:
getShardListin interfaceKinesisProxyInterface- 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:KinesisProxyInterfaceGet a shard iterator from the specified position in a shard. The retrieved shard iterator can be used inKinesisProxyInterface.getRecords(String, int)} to read data from the Kinesis shard.- Specified by:
getShardIteratorin interfaceKinesisProxyInterface- Parameters:
shard- the shard to get the iteratorshardIteratorType- 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 benullif shardIteratorType is TRIM_HORIZON or LATEST, should be aDatevalue if shardIteratorType is AT_TIMESTAMP, should be aStringrepresenting 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:
trueif the exception can be recovered from, elsefalse
-
isRecoverableException
protected static boolean isRecoverableException(com.amazonaws.AmazonServiceException ex)
Determines whether the exception is recoverable using exponential-backoff.- Parameters:
ex- Exception to inspect- Returns:
trueif the exception can be recovered from, elsefalse
-
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 describestartShardId- which shard to start with for this describe operation- Returns:
- the result of the describe stream operation
- Throws:
InterruptedException
-
-