[
https://issues.apache.org/jira/browse/BEAM-8511?focusedWorklogId=344432&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-344432
]
ASF GitHub Bot logged work on BEAM-8511:
----------------------------------------
Author: ASF GitHub Bot
Created on: 15/Nov/19 17:26
Start Date: 15/Nov/19 17:26
Worklog Time Spent: 10m
Work Description: aromanenko-dev commented on pull request #9899:
[BEAM-8511] [WIP] KinesisIO.Read enhanced fanout
URL: https://github.com/apache/beam/pull/9899#discussion_r346852031
##########
File path:
sdks/java/io/kinesis2/src/main/java/org/apache/beam/sdk/io/kinesis2/KinesisIO.java
##########
@@ -0,0 +1,378 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.kinesis2;
+
+import static
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+
+import com.google.auto.value.AutoValue;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.io.Read.Unbounded;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.values.PBegin;
+import org.apache.beam.sdk.values.PCollection;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.kinesis.common.InitialPositionInStream;
+
+/**
+ * {@link PTransform}s for reading from and writing to <a
+ * href="https://aws.amazon.com/kinesis/">Kinesis</a> streams.
+ *
+ * <h3>Reading from Kinesis</h3>
+ *
+ * <p>Example usage:
+ *
+ * <pre>{@code
+ * p.apply(KinesisIO.read()
+ * .withStreamName("streamName")
+ * .withInitialPositionInStream(InitialPositionInStream.LATEST)
+ * .withAWSClientsProvider("AWS_KEY", _"AWS_SECRET", STREAM_REGION)
+ * .apply( ... ) // other transformations
+ * }</pre>
+ *
+ * <p>As you can see you need to provide 3 things:
+ *
+ * <ul>
+ * <li>name of the stream you're going to read
+ * <li>position in the stream where reading should start. There are two
options:
+ * <ul>
+ * <li>{@link InitialPositionInStream#LATEST} - reading will begin
from end of the stream
+ * <li>{@link InitialPositionInStream#TRIM_HORIZON} - reading will
begin at the very
+ * beginning of the stream
+ * </ul>
+ * <li>data used to initialize {@link KinesisClient} and {@link
CloudWatchClient} clients:
+ * <ul>
+ * <li>credentials (aws key, aws secret)
+ * <li>region where the stream is located
+ * </ul>
+ * </ul>
+ *
+ * <p>In case when you want to set up {@link KinesisClient} or {@link
CloudWatchClient} client by
+ * your own (for example if you're using more sophisticated authorization
methods like Amazon STS,
+ * etc.) you can do it by implementing {@link AWSClientsProvider} class:
+ *
+ * <pre>{@code
+ * public class MyCustomKinesisClientProvider implements AWSClientsProvider {
+ * {@literal @}Override
+ * public KinesisClient getKinesisClient() {
+ * // set up your client here
+ * }
+ *
+ * public CloudWatchClient getCloudWatchClient() {
+ * // set up your client here
+ * }
+ *
+ * }
+ * }</pre>
+ *
+ * <p>Usage is pretty straightforward:
+ *
+ * <pre>{@code
+ * p.apply(KinesisIO.read()
+ * .withStreamName("streamName")
+ * .withInitialPositionInStream(InitialPositionInStream.LATEST)
+ * .withAWSClientsProvider(new MyCustomKinesisClientProvider())
+ * .apply( ... ) // other transformations
+ * }</pre>
+ *
+ * <p>There’s also possibility to start reading using arbitrary point in time
- in this case you
+ * need to provide {@link Instant} object:
+ *
+ * <pre>{@code
+ * p.apply(KinesisIO.read()
+ * .withStreamName("streamName")
+ * .withInitialTimestampInStream(instant)
+ * .withAWSClientsProvider(new MyCustomKinesisClientProvider())
+ * .apply( ... ) // other transformations
+ * }</pre>
+ *
+ * <p>Kinesis IO uses ArrivalTimeWatermarkPolicy by default. To use Processing
time as event time:
+ *
+ * <pre>{@code
+ * p.apply(KinesisIO.read()
+ * .withStreamName("streamName")
+ * .withInitialPositionInStream(InitialPositionInStream.LATEST)
+ * .withProcessingTimeWatermarkPolicy())
+ * }</pre>
+ *
+ * <p>It is also possible to specify a custom watermark policy to control
watermark computation.
+ * Below is an example
+ *
+ * <pre>{@code
+ * // custom policy
+ * class MyCustomPolicy implements WatermarkPolicy {
+ * private WatermarkPolicyFactory.CustomWatermarkPolicy
customWatermarkPolicy;
+ *
+ * MyCustomPolicy() {
+ * this.customWatermarkPolicy = new
WatermarkPolicyFactory.CustomWatermarkPolicy(WatermarkParameters.create());
+ * }
+ *
+ * @Override
+ * public Instant getWatermark() {
+ * return customWatermarkPolicy.getWatermark();
+ * }
+ *
+ * @Override
+ * public void update(KinesisRecord record) {
+ * customWatermarkPolicy.update(record);
+ * }
+ * }
+ *
+ * // custom factory
+ * class MyCustomPolicyFactory implements WatermarkPolicyFactory {
+ * @Override
+ * public WatermarkPolicy createWatermarkPolicy() {
+ * return new MyCustomPolicy();
+ * }
+ * }
+ *
+ * p.apply(KinesisIO.read()
+ * .withStreamName("streamName")
+ * .withInitialPositionInStream(InitialPositionInStream.LATEST)
+ * .withCustomWatermarkPolicy(new MyCustomPolicyFactory())
+ * }</pre>
+ */
Review comment:
Please, add a quick example that shows using `withConsumerArn()`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 344432)
Time Spent: 2h 20m (was: 2h 10m)
> Support for enhanced fan-out in KinesisIO.Read
> ----------------------------------------------
>
> Key: BEAM-8511
> URL: https://issues.apache.org/jira/browse/BEAM-8511
> Project: Beam
> Issue Type: New Feature
> Components: io-java-kinesis
> Reporter: Jonothan Farr
> Assignee: Jonothan Farr
> Priority: Major
> Time Spent: 2h 20m
> Remaining Estimate: 0h
>
> Add support for reading from an enhanced fan-out consumer using KinesisIO.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)