[[AWS-KINESIS-KinesisComponent]]
Kinesis Component
~~~~~~~~~~~~~~~~~

*Available as of Camel 2.17*

The Kinesis component supports receiving messages from Amazon Kinesis
service.

Prerequisites

You must have a valid Amazon Web Services developer account, and be
signed up to use Amazon Kinesis. More information are available
at http://aws.amazon.com/kinesis/[AWS Kinesis]

[[AWS-KINESIS-URIFormat]]
URI Format
^^^^^^^^^^

[source,java]
-----------------------------------
aws-kinesis://stream-name[?options]
-----------------------------------

The stream needs to be created prior to it being used. +
 You can append query options to the URI in the following format,
?options=value&option2=value&...

[[AWS-KINESIS-URIOptions]]
URI Options
^^^^^^^^^^^

[width="100%",cols="10%,10%,10%,70%",options="header",]
|=======================================================================
|Name |Default Value |Context |Description

|amazonKinesisClient |`null` |Consumer |Reference to a `com.amazonaws.services.kinesis.AmazonKinesisClient` in
the link:registry.html[Registry].

|maxMessagesPerPoll |`100` |Consumer |Maximum results that will be returned in each poll to the AWS API, Given
that the shard iterator is unique to the consumer, changing it shouldn't
effect other consumers.

|iteratorType |`TRIM_HORIZON` |Consumer |One of trim_horizon or latest. See
http://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html[http://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html]
for descriptions of these two iterator types.
|=======================================================================

Required Kinesis component options

You have to provide the amazonKinesisClient in the
link:registry.html[Registry] with proxies and relevant credentials
configured.

[[AWS-KINESIS-BatchConsumer]]
Batch Consumer
^^^^^^^^^^^^^^

This component implements the link:batch-consumer.html[Batch Consumer].

This allows you for instance to know how many messages exists in this
batch and for instance let the link:aggregator.html[Aggregator]
aggregate this number of messages.

[[AWS-KINESIS-Usage]]
Usage
^^^^^

[[AWS-KINESIS-MessageheaderssetbytheKinesisconsumer]]
Message headers set by the Kinesis consumer
+++++++++++++++++++++++++++++++++++++++++++

[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|Header |Type |Description

|`CamelAwsKinesisSequenceNumber` |`String` |The sequence number of the record. This is represented as a String as it
size is not defined by the API. If it is to be used as a numerical type
then use

|`CamelAwsKinesisApproximateArrivalTimestamp` |`String` |The time AWS assigned as the arrival time of the record.

|`CamelAwsKinesisPartitionKey` |`String` |Identifies which shard in the stream the data record is assigned to.
|=======================================================================

[[AWS-KINESIS-AmazonKinesisconfiguration]]
AmazonKinesis configuration
+++++++++++++++++++++++++++

You will need to create an instance of AmazonDynamoDBStreamsClient and
bind it to the registry

[source,java]
--------------------------------------------------------------------------------------------------------------------
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setProxyHost("http://myProxyHost");
clientConfiguration.setProxyPort(8080);

Region region = Region.getRegion(Regions.fromName(region));
region.createClient(AmazonDynamoDBStreamsClient.class, null, clientConfiguration);
// the 'null' here is the AWSCredentialsProvider which defaults to an instance of DefaultAWSCredentialsProviderChain

registry.bind("kinesisClient", client);
--------------------------------------------------------------------------------------------------------------------

[[AWS-KINESIS-ProvidingAWSCredentials]]
Providing AWS Credentials
+++++++++++++++++++++++++

It is recommended that the credentials are obtained by using the
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html[DefaultAWSCredentialsProviderChain]
that is the default when creating a new ClientConfiguration instance,
however, a
different http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/AWSCredentialsProvider.html[AWSCredentialsProvider]
can be specified when calling createClient(...).

[[AWS-Kinesis-MessageheaderssetbytheKinesisproducer]]
Message headers used by the Kinesis producer to write to Kinesis.  The producer expects that the message body is a `ByteBuffer`.
+++++++++++++++++++++++++++++++++++++++

[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|Header |Type |Description

|`CamelAwsKinesisPartitionKey` |`String` |The PartitionKey to pass to Kinesis to store this record.

|`CamelAwsKinesisSequenceNumber` |`String` |Optional paramter to indicate the sequence number of this record.

|=======================================================================

Message headers set by the Kinesis producer on successful storage of a Record
+++++++++++++++++++++++++++++++++++++++

[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|Header |Type |Description

|`CamelAwsKinesisSequenceNumber` |`String` |The sequence number of the record, as defined in
http://docs.aws.amazon.com/kinesis/latest/APIReference/API_PutRecord.html#API_PutRecord_ResponseSyntax[Response Syntax]

|`CamelAwsKinesisShardId` |`String` |The shard ID of where the Record was stored


|=======================================================================

[[AWS-KINESIS-Dependencies]]
Dependencies
^^^^^^^^^^^^

Maven users will need to add the following dependency to their pom.xml.

*pom.xml*

[source,xml]
---------------------------------------
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-aws</artifactId>
    <version>${camel-version}</version>
</dependency>
---------------------------------------

where `${camel-version`} must be replaced by the actual version of Camel
(2.17 or higher).

[[AWS-KINESIS-SeeAlso]]
See Also
^^^^^^^^

* link:configuring-camel.html[Configuring Camel]
* link:component.html[Component]
* link:endpoint.html[Endpoint]
* link:getting-started.html[Getting Started]

* link:aws.html[AWS Component]

