@Experimental(value=SOURCE_SINK) public final class KinesisIO extends java.lang.Object
PTransform
s for reading from and writing to Kinesis streams.
Example usage:
p.apply(KinesisIO.read()
.withStreamName("streamName")
.withInitialPositionInStream(InitialPositionInStream.LATEST)
.withAWSClientsProvider("AWS_KEY", _"AWS_SECRET", STREAM_REGION)
.apply( ... ) // other transformations
As you can see you need to provide 3 things:
InitialPositionInStream.LATEST
- reading will begin from end of the stream
InitialPositionInStream.TRIM_HORIZON
- reading will begin at the very
beginning of the stream
AmazonKinesis
and AmazonCloudWatch
clients:
In case when you want to set up AmazonKinesis
or AmazonCloudWatch
client by
your own (for example if you're using more sophisticated authorization methods like Amazon STS,
etc.) you can do it by implementing AWSClientsProvider
class:
public class MyCustomKinesisClientProvider implements AWSClientsProvider {
{@literal @}Override
public AmazonKinesis getKinesisClient() {
// set up your client here
}
public AmazonCloudWatch getCloudWatchClient() {
// set up your client here
}
}
Usage is pretty straightforward:
p.apply(KinesisIO.read()
.withStreamName("streamName")
.withInitialPositionInStream(InitialPositionInStream.LATEST)
.withAWSClientsProvider(new MyCustomKinesisClientProvider())
.apply( ... ) // other transformations
There’s also possibility to start reading using arbitrary point in time - in this case you
need to provide Instant
object:
p.apply(KinesisIO.read()
.withStreamName("streamName")
.withInitialTimestampInStream(instant)
.withAWSClientsProvider(new MyCustomKinesisClientProvider())
.apply( ... ) // other transformations
Kinesis IO uses ArrivalTimeWatermarkPolicy by default. To use Processing time as event time:
p.apply(KinesisIO.read()
.withStreamName("streamName")
.withInitialPositionInStream(InitialPositionInStream.LATEST)
.withProcessingTimeWatermarkPolicy())
It is also possible to specify a custom watermark policy to control watermark computation. Below is an example
// custom policy class MyCustomPolicy implements WatermarkPolicy { private WatermarkPolicyFactory.CustomWatermarkPolicy customWatermarkPolicy; MyCustomPolicy() { this.customWatermarkPolicy = new WatermarkPolicyFactory.CustomWatermarkPolicy(WatermarkParameters.create()); }
Modifier and Type | Class and Description |
---|---|
static class |
KinesisIO.Read
Implementation of
read() . |
static class |
KinesisIO.Write
Implementation of
write() . |
Constructor and Description |
---|
KinesisIO() |
Modifier and Type | Method and Description |
---|---|
static KinesisIO.Read |
read()
Returns a new
KinesisIO.Read transform for reading from Kinesis. |
static KinesisIO.Write |
write()
A
PTransform writing data to Kinesis. |
public static KinesisIO.Read read()
KinesisIO.Read
transform for reading from Kinesis.public static KinesisIO.Write write()
PTransform
writing data to Kinesis.