Our example use case simulates sales data coming from the field, and being processed via a Kinesis stream and written out into ElasticSearch where we can analyse the sales data graphically with Kibana. The sales data will be read from a CSV file, and have costs, quantities and transaction dates randomly applied. The architecture looks like this:
Contents
KinesisConsumer
Sample application that consumes messages from a Kinesis stream and writes them to an ElasticSearch domain index
.The empty repository will be cloned into the local filesystem path you specified.
public static final String ELASTICSEARCH_ENDPOINT
to match the value in value from Cloudformation Output tab, called ElasticsearchEndpoint. By default, the value is set to REPLACE_WITH_YOUR_ELASTIC_SEARCH_ENDPOINT. Erase this value and replace it with your ElasticsearchEndpoint value. Save the file.cd
into the folder where you cloned the repository.git checkout -b master
git add .
git commit -m "Initial commit"
If this option does not appear, or the branch Master is not present, you may need to use the refresh action to update the IDE.
You should see the files that you have added into the repository listed in the browser view.
The labs setup has provisioned an EC2 instance for you to run as the Consumer in this scenario. You will now connect to the EC2 instance, clone the repository, build and run the Consumer code.
chmod 400 <path to your downloaded PEM file>
Example:
chmod 400 ~/Downloads/ee-default-keypair.pem
Leave the terminal session open, you will return shortly.
ssh -i <path to your downloaded PEM file> ec2-user@<EC2InstanceKinesisConsumer>
Example:
ssh -i ~/Downloads/ee-default-keypair.pem ec2-user@34.212.21.7
Don’t include the < and > symbols. If you have difficulty with this step please seek help from a lab assistant. Once you have successfully logged on to the instance via SSH, continue below.
git clone https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/KinesisConsumer
You will be asked for username and password. You can obtain these from Cloudformation Outputs tab - look for GitUsername and GitPassword.
/opt/apache-maven-3.3.9/bin/mvn package shade:shade
It will take a few moments to complete the build.
java -jar target/KinesisConsumerApp-1.0.0.jar
The application will start and wait for events to be published into the Kinesis stream. You should see no errors, and after a few moments, the console output should show ‘Sleeping…’ since there are no records in the stream to process:
INFO: Initializing record processor for shard: shardId-000000000000
Aug 21, 2017 11:30:19 AM idevelop.demo.RecordProcessor initialize
INFO: Initializing record processor for shard: shardId-000000000001
Aug 21, 2017 11:30:57 AM com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker info
INFO: Current stream shard assignments: shardId-000000000001, shardId-000000000000
Aug 21, 2017 11:30:57 AM com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker info
INFO: Sleeping ...
Stop the execution in the terminal window by issuing CTRL + C
You will now repeat the process above, this time, creating a repository for the Kinesis Producer application, and cloning it on to the Kinesis Producer EC2 instance. Once this is complete, you can begin testing data transfer between the two machines, via Amazon Kinesis.
The process of creating the repository is the same as the previous steps, but we repeat it here for convenience.
KinesisProducer
Sample application that publishes sales events into a Kinesis stream
.In the Eclipse IDE, open the Git Perspective. If you don’t already have a shortcut to this perspective, use the Window | Perspective | Open Perspective menu option.
Click the Clone repository icon (tooltip: Clone a repository and add the clone to this view)
In the AWS CodeCommit console in the browser, click the Clone URL button. Copy the clone URL for HTTPS into your clipboard.
Back in the Eclipse IDE, paste the clone URL into the URI field.
The credentials you used in the previous steps should still be populated in the Authentication section - but if not, for User paste in the GitUsername value from Cloudformation Outputs tab. For the Password field, paste in the GitPassword value from Cloudformation Output tab.
Click Next
In Branch Selection, there are no branches created, so just click Next.
In the Local destination panel, select a suitable path on your development filesystem and click Finish:
The empty repository will be cloned into the local filesystem path you specified.
Download the source code bundle from KinesisProducer.zip and explode the zip file onto your filesystem.
Copy the contents of the exploded zip file across to the filesystem location where you have cloned the KinesisProducer repository.
Open a terminal window and cd
into the folder where you cloned the repository.
Create a new master branch by issuing the command:
git checkout -b master
git add .
git commit -m "Initial commit"
The branch will be pushed to the CodeCommit repository. Confirm this by refreshing the CodeCommit console in the web browser. You should see the files that you have added into the repository listed in the browser view.