List of usage examples for com.amazonaws.services.kinesis AmazonKinesisClient AmazonKinesisClient
AmazonKinesisClient(AwsSyncClientParams clientParams)
From source file:AmazonKinesisSample.java
License:Open Source License
private static void init() throws Exception { /*/*from w w w . j a v a2 s . co m*/ * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } kinesisClient = new AmazonKinesisClient(credentials); }
From source file:kinesisAlertAnalysis.java
License:Open Source License
private static void init() throws Exception { /*//from w ww . ja v a 2s . c o m * The ProfileCredentialsProvider will return your [awsReilly] * credential profile by reading from the credentials file located at * (/Users/johnreilly/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("jreilly").getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (/Users/johnreilly/.aws/credentials), and is in valid format.", e); } kinesis = new AmazonKinesisClient(credentials); }
From source file:AmazonKinesisAuditVerify.java
License:Open Source License
public static void deleteResources() { AWSCredentials credentials = credentialsProvider.getCredentials(); // Delete the stream AmazonKinesis kinesis = new AmazonKinesisClient(credentials); System.out.printf("Deleting the Amazon Kinesis stream used by the sample. Stream Name = %s.\n", SAMPLE_APPLICATION_STREAM_NAME); try {// w w w . j a va2s . c o m kinesis.deleteStream(SAMPLE_APPLICATION_STREAM_NAME); } catch (ResourceNotFoundException ex) { // The stream doesn't exist. } // Delete the table AmazonDynamoDBClient dynamoDB = new AmazonDynamoDBClient(credentialsProvider.getCredentials()); System.out.printf( "Deleting the Amazon DynamoDB table used by the Amazon Kinesis Client Library. Table Name = %s.\n", SAMPLE_APPLICATION_NAME); try { dynamoDB.deleteTable(SAMPLE_APPLICATION_NAME); } catch (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException ex) { // The table doesn't exist. } }
From source file:sqsAlertStream.java
License:Open Source License
public static void main(String[] args) throws Exception { // get credentials String user = "jreilly"; AWSCredentials credentials = whgHelper.getCred(user); // use credentials to set access to SQS AmazonSQS sqs = whgHelper.setQueueAccess(credentials); // define queue that messages will be retrieved from String thisQueue = "alertStream"; String nextQueue = "alertErrorHandling"; // set access to stream instance kinesis = new AmazonKinesisClient(credentials); final String streamName = "alertsStream"; final Integer streamSize = 1; while (1 > 0) { // pull list of current messages (up to 10) in the queue List<Message> messages = whgHelper.getMessagesFromQueue(thisQueue, sqs); System.out.println("Count of messages in " + thisQueue + ": " + messages.size()); try {//from www . j a va 2s .c o m for (Message message : messages) { whgHelper.printMessage(message); for (Entry<String, String> entry : message.getAttributes().entrySet()) { whgHelper.printMessageEntry(entry); } // Write record to the stream long createTime = System.currentTimeMillis(); PutRecordRequest putRecordRequest = new PutRecordRequest(); putRecordRequest.setStreamName(streamName); putRecordRequest .setData(ByteBuffer.wrap(String.format(message.getBody(), createTime).getBytes())); putRecordRequest.setPartitionKey(String.format("partitionKey-%d", createTime)); PutRecordResult putRecordResult = kinesis.putRecord(putRecordRequest); System.out.printf( "Successfully put record, partition key : %s, ShardID : %s, SequenceNumber : %s.\n", putRecordRequest.getPartitionKey(), putRecordResult.getShardId(), putRecordResult.getSequenceNumber()); // then send message to cache queue System.out.println("Sending messages to next queue."); sqs.sendMessage(new SendMessageRequest(nextQueue, message.getBody())); // delete message after sending to persist queue System.out.println("Deleting message from this queue.\n"); String messageRecieptHandle = message.getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(thisQueue, messageRecieptHandle)); } Thread.sleep(20000); // do nothing for 1000 miliseconds (1 second) } catch (AmazonServiceException ase) { whgHelper.errorMessagesAse(ase); } catch (AmazonClientException ace) { whgHelper.errorMessagesAce(ace); } } }
From source file:KinesisStreamDataProducer.java
License:Open Source License
private static void init() throws Exception { kinesisClient = new AmazonKinesisClient(new DefaultAWSCredentialsProviderChain()); }
From source file:AmazonKinesisRecordProducerSample.java
License:Open Source License
private static void init() throws Exception { /*//from w w w .j a v a 2 s.c o m * The ProfileCredentialsProvider will return your [haow2] * credential profile by reading from the credentials file located at * (/Users/Dawn/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("haow2").getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (/Users/Dawn/.aws/credentials), and is in valid format.", e); } kinesis = new AmazonKinesisClient(credentials); }
From source file:awskinesis.AmazonKinesisApplicationSample.java
License:Apache License
public static void deleteResources() { AWSCredentials credentials = credentialsProvider.getCredentials(); // Delete the stream AmazonKinesis kinesis = new AmazonKinesisClient(credentials); kinesis.setEndpoint("kinesis.cn-north-1.amazonaws.com.cn"); System.out.printf("Deleting the Amazon Kinesis stream used by the sample. Stream Name = %s.\n", SAMPLE_APPLICATION_STREAM_NAME); try {//from www . j a v a2s. co m kinesis.deleteStream(SAMPLE_APPLICATION_STREAM_NAME); } catch (ResourceNotFoundException ex) { // The stream doesn't exist. } // Delete the table AmazonDynamoDBClient dynamoDB = new AmazonDynamoDBClient(credentialsProvider.getCredentials()); dynamoDB.setEndpoint("dynamodb.cn-north-1.amazonaws.com.cn"); System.out.printf( "Deleting the Amazon DynamoDB table used by the Amazon Kinesis Client Library. Table Name = %s.\n", SAMPLE_APPLICATION_NAME); try { dynamoDB.deleteTable(SAMPLE_APPLICATION_NAME); } catch (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException ex) { // The table doesn't exist. } }
From source file:awskinesis.AmazonKinesisRecordProducerSample.java
License:Apache License
private static void init() throws Exception { /*//from ww w .java 2s .c o m * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } kinesis = new AmazonKinesisClient(credentials); kinesis.setEndpoint("kinesis.cn-north-1.amazonaws.com.cn"); }
From source file:com.amazon.services.awsrum.utils.KinesisUtils.java
License:Open Source License
/** * Creates the Kinesis stream specified by config.KINESIS_INPUT_STREAM * /*from w w w . jav a 2 s . co m*/ * @param config * The configuration with the specified input stream name and * {@link AWSCredentialsProvider} * @param shardCount * The shard count to create the stream with */ public static void createInputStream(KinesisConnectorConfiguration config, int shardCount) { AmazonKinesisClient kinesisClient = new AmazonKinesisClient(config.AWS_CREDENTIALS_PROVIDER); kinesisClient.setEndpoint(config.KINESIS_ENDPOINT); createAndWaitForStreamToBecomeAvailable(kinesisClient, config.KINESIS_INPUT_STREAM, shardCount); }
From source file:com.amazon.services.awsrum.utils.KinesisUtils.java
License:Open Source License
/** * Creates the Kinesis stream specified by config.KINESIS_OUTPUT_STREAM. * //w w w. j ava2 s . c o m * @param config * The configuration with the specified output stream name and * {@link AWSCredentialsProvider} * @param shardCount * The shard count to create the stream with */ public static void createOutputStream(KinesisConnectorConfiguration config, int shardCount) { AmazonKinesisClient kinesisClient = new AmazonKinesisClient(config.AWS_CREDENTIALS_PROVIDER); kinesisClient.setEndpoint(config.KINESIS_ENDPOINT); createAndWaitForStreamToBecomeAvailable(kinesisClient, config.KINESIS_OUTPUT_STREAM, shardCount); }