Java tutorial
/* * Copyright (C) 2016 An Honest Effort LLC. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package io.radiowitness.kinesis.consumer; import com.amazonaws.ClientConfiguration; import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.internal.StaticCredentialsProvider; import com.amazonaws.services.kinesis.clientlibrary.lib.worker.KinesisClientLibConfiguration; import java.util.UUID; public class KclConfigFactory { private final KinesisConsumerConfig config; public KclConfigFactory(KinesisConsumerConfig config) { this.config = config; } private AWSCredentialsProvider credentials() { return new StaticCredentialsProvider( new BasicAWSCredentials(config.getAccessKeyId(), config.getSecretKey())); } private String userAgent() { StringBuilder userAgent = new StringBuilder(ClientConfiguration.DEFAULT_USER_AGENT); userAgent.append(" "); userAgent.append(config.getAppName()); userAgent.append(" "); userAgent.append(config.getAppVersion()); return userAgent.toString(); } public KinesisClientLibConfiguration create() { return new KinesisClientLibConfiguration(config.getAppName(), config.getStreamName(), credentials(), UUID.randomUUID().toString()).withRegionName(config.getRegion().getName()) .withUserAgent(userAgent()).withIdleTimeBetweenReadsInMillis(config.getReadIntervalMs()) .withValidateSequenceNumberBeforeCheckpointing(false); } }