From f7f98a4bc6d87178dc9db06487f1d824a25880d4 Mon Sep 17 00:00:00 2001 From: Harlow Ward Date: Tue, 9 Apr 2019 22:10:07 -0700 Subject: [PATCH] Default the consumer library to read from latest Having consumers start at latest record seems like a reasonable default. This can also be overridden with optional config, make sure that is documented for users of the library. Fixes: https://github.com/harlow/kinesis-consumer/issues/86 --- README.md | 16 ++++++++++++++++ consumer.go | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bfbae2c..779b560 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,22 @@ The [expvar package](https://golang.org/pkg/expvar/) will display consumer count }, ``` +### Consumer starting point + +Kinesis allows consumers to specify where on the stream they'd like to start consuming from. The default in this library is `LATEST` (Start reading just after the most recent record in the shard). + +This can be adjusted by using the `WithShardIteratorType` option in the library: + +```go +// override starting place on stream to use TRIM_HORIZON +c, err := consumer.New( + *stream, + consumer.WithShardIteratorType(kinesis.ShardIteratorTypeTrimHorizon) +) +``` + +[See AWS Docs for more options.](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html) + ### Logging Logging supports the basic built-in logging library or use thrid party external one, so long as diff --git a/consumer.go b/consumer.go index adbb000..e9c583a 100644 --- a/consumer.go +++ b/consumer.go @@ -26,7 +26,7 @@ func New(streamName string, opts ...Option) (*Consumer, error) { // new consumer with no-op checkpoint, counter, and logger c := &Consumer{ streamName: streamName, - initialShardIteratorType: kinesis.ShardIteratorTypeTrimHorizon, + initialShardIteratorType: kinesis.ShardIteratorTypeLatest, checkpoint: &noopCheckpoint{}, counter: &noopCounter{}, logger: &noopLogger{