Search in sources :

Example 6 with KinesisProducerConfiguration

use of com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration in project flink by apache.

the class KinesisConfigUtil method getValidatedProducerConfiguration.

/**
 * Validate configuration properties for {@link FlinkKinesisProducer}, and return a constructed
 * KinesisProducerConfiguration.
 */
public static KinesisProducerConfiguration getValidatedProducerConfiguration(Properties config) {
    checkNotNull(config, "config can not be null");
    validateAwsConfiguration(config);
    if (!config.containsKey(AWSConfigConstants.AWS_REGION)) {
        // per requirement in Amazon Kinesis Producer Library
        throw new IllegalArgumentException(String.format("For FlinkKinesisProducer AWS region ('%s') must be set in the config.", AWSConfigConstants.AWS_REGION));
    }
    KinesisProducerConfiguration kpc = KinesisProducerConfiguration.fromProperties(config);
    kpc.setRegion(config.getProperty(AWSConfigConstants.AWS_REGION));
    kpc.setCredentialsProvider(AWSUtil.getCredentialsProvider(config));
    // we explicitly lower the credential refresh delay (default is 5 seconds)
    // to avoid an ignorable interruption warning that occurs when shutting down the
    // KPL client. See https://github.com/awslabs/amazon-kinesis-producer/issues/10.
    kpc.setCredentialsRefreshDelay(100);
    // Override default values if they aren't specified by users
    if (!config.containsKey(RATE_LIMIT)) {
        kpc.setRateLimit(DEFAULT_RATE_LIMIT);
    }
    if (!config.containsKey(THREADING_MODEL)) {
        kpc.setThreadingModel(DEFAULT_THREADING_MODEL);
    }
    if (!config.containsKey(THREAD_POOL_SIZE)) {
        kpc.setThreadPoolSize(DEFAULT_THREAD_POOL_SIZE);
    }
    return kpc;
}
Also used : KinesisProducerConfiguration(com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration)

Aggregations

KinesisProducerConfiguration (com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration)6 Properties (java.util.Properties)5 Test (org.junit.Test)4 AwsSdkMetrics (com.amazonaws.metrics.AwsSdkMetrics)1 Attempt (com.amazonaws.services.kinesis.producer.Attempt)1 KinesisProducer (com.amazonaws.services.kinesis.producer.KinesisProducer)1 UserRecordFailedException (com.amazonaws.services.kinesis.producer.UserRecordFailedException)1 UserRecordResult (com.amazonaws.services.kinesis.producer.UserRecordResult)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 Field (java.lang.reflect.Field)1 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 PublicEvolving (org.apache.flink.annotation.PublicEvolving)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 RuntimeContext (org.apache.flink.api.common.functions.RuntimeContext)1