Java Code Examples for com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream#valueOf()
The following examples show how to use
com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream#valueOf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KinesisEventConsumer.java From koupler with MIT License | 5 votes |
public KinesisEventConsumer(String propertiesFile, String streamName, String appName, String initialPosition) { KinesisProducerConfiguration config = KinesisProducerConfiguration.fromPropertiesFile(propertiesFile); InitialPositionInStream position = InitialPositionInStream.valueOf(initialPosition); KinesisClientLibConfiguration clientConfig = new KinesisClientLibConfiguration(appName, streamName, new DefaultAWSCredentialsProviderChain(), appName) .withRegionName(config.getRegion()) .withInitialPositionInStream(position); this.builder = new Worker.Builder().recordProcessorFactory(this).config(clientConfig); }
Example 2
Source File: KinesisConnectorConfiguration.java From amazon-kinesis-connectors with Apache License 2.0 | 5 votes |
private InitialPositionInStream getInitialPositionInStreamProperty(String property, InitialPositionInStream defaultInitialPositionInInputStream, Properties properties) { String propertyValue = properties.getProperty(property, defaultInitialPositionInInputStream.toString()); try { return InitialPositionInStream.valueOf(propertyValue); } catch (Exception e) { LOG.error(e); return defaultInitialPositionInInputStream; } }
Example 3
Source File: ManagedConsumer.java From aws-big-data-blog with Apache License 2.0 | 4 votes |
public void configure() throws Exception { if (!isConfigured) { validateConfig(); try { String userAgent = "AWSKinesisManagedConsumer/" + this.version; if (this.positionInStream != null) { streamPosition = InitialPositionInStream.valueOf(this.positionInStream); } else { streamPosition = InitialPositionInStream.LATEST; } // append the environment name to the application name if (environmentName != null) { appName = String.format("%s-%s", appName, environmentName); } // ensure the JVM will refresh the cached IP values of AWS // resources // (e.g. service endpoints). java.security.Security.setProperty("networkaddress.cache.ttl", "60"); String workerId = NetworkInterface.getNetworkInterfaces() + ":" + UUID.randomUUID(); LOG.info("Using Worker ID: " + workerId); // obtain credentials using the default provider chain or the // credentials provider supplied AWSCredentialsProvider credentialsProvider = this.credentialsProvider == null ? new DefaultAWSCredentialsProviderChain() : this.credentialsProvider; LOG.info("Using credentials with Access Key ID: " + credentialsProvider.getCredentials().getAWSAccessKeyId()); config = new KinesisClientLibConfiguration(appName, streamName, credentialsProvider, workerId).withInitialPositionInStream(streamPosition).withKinesisEndpoint( kinesisEndpoint); config.getKinesisClientConfiguration().setUserAgent(userAgent); if (regionName != null) { Region region = Region.getRegion(Regions.fromName(regionName)); config.withRegionName(region.getName()); } if (this.maxRecords != -1) config.withMaxRecords(maxRecords); if (this.positionInStream != null) config.withInitialPositionInStream(InitialPositionInStream.valueOf(this.positionInStream)); LOG.info(String.format( "Amazon Kinesis Managed Client prepared for %s on %s in %s (%s) using %s Max Records", config.getApplicationName(), config.getStreamName(), config.getRegionName(), config.getWorkerIdentifier(), config.getMaxRecords())); isConfigured = true; } catch (Exception e) { throw new InvalidConfigurationException(e); } } }
Example 4
Source File: KinesisApplication.java From aws-big-data-blog with Apache License 2.0 | 4 votes |
/** * @param propertiesFile * @throws IOException Thrown when we run into issues reading properties */ private static void loadProperties(String propertiesFile) throws IOException { FileInputStream inputStream = new FileInputStream(propertiesFile); Properties properties = new Properties(); try { properties.load(inputStream); } finally { inputStream.close(); } String appNameOverride = properties.getProperty(ConfigKeys.APPLICATION_NAME_KEY); if (appNameOverride != null) { applicationName = appNameOverride; } LOG.info("Using application name " + applicationName); String streamNameOverride = properties.getProperty(ConfigKeys.STREAM_NAME_KEY); if (streamNameOverride != null) { streamName = streamNameOverride; } LOG.info("Using stream name " + streamName); String kinesisEndpointOverride = properties.getProperty(ConfigKeys.KINESIS_ENDPOINT_KEY); if (kinesisEndpointOverride != null) { kinesisEndpoint = kinesisEndpointOverride; } LOG.info("Using Kinesis endpoint " + kinesisEndpoint); String initialPositionOverride = properties.getProperty(ConfigKeys.INITIAL_POSITION_IN_STREAM_KEY); if (initialPositionOverride != null) { initialPositionInStream = InitialPositionInStream.valueOf(initialPositionOverride); } LOG.info("Using initial position " + initialPositionInStream.toString() + " (if a checkpoint is not found)."); String redisEndpointOverride = properties.getProperty(ConfigKeys.REDIS_ENDPOINT); if (redisEndpointOverride != null) { redisEndpoint = redisEndpointOverride; } LOG.info("Using Redis endpoint " + redisEndpoint); String redisPortOverride = properties.getProperty(ConfigKeys.REDIS_PORT); if (redisPortOverride != null) { try { redisPort = Integer.parseInt(redisPortOverride); } catch(Exception e) { } } LOG.info("Using Redis port " + redisPort); }