- Language: Go (
go 1.13ingo.mod) - Module:
github.com/harlow/kinesis-consumer - Purpose: lightweight Kinesis consumer with pluggable checkpoint stores
- AWS SDK: v2 (
github.com/aws/aws-sdk-go-v2/...)
- Main consumer type:
Consumerinconsumer.go - Constructor:
New(streamName string, opts ...Option)inconsumer.go - Default behavior:
- Shard iterator type defaults to
LATEST Store,Logger, andCounterare no-op by default- Scan interval default is
250ms - Max records per
GetRecordsdefaults to10000 - Group defaults to
AllGroup(consumes all shards, discovers new shards)
- Shard iterator type defaults to
- Main scan APIs:
Scan(ctx, fn)scans all shards concurrentlyScanShard(ctx, shardID, fn)scans one shard
AllGroup(allgroup.go) pollsListShardsevery 30 seconds.- It tracks parent shard dependencies and waits for parent close before processing child shards.
- If group implements
CloseableGroup,ConsumercallsCloseShardafter shard processing exits. - Closed shard behavior:
- Detected when next shard iterator is
nilor unchanged. - Optional callback:
WithShardClosedHandler(...).
- Detected when next shard iterator is
- Interfaces:
Storeinstore.goGroupingroup.go
- Built-in stores:
- Memory:
store/memory(in-process only) - Redis:
store/redis - DynamoDB:
store/ddb - Postgres:
store/postgres - MySQL:
store/mysql
- Memory:
- Important persistence detail:
- DDB/Postgres/MySQL stores buffer checkpoints in memory and flush periodically (default 1 minute).
- Call
Shutdown()on those stores in graceful shutdown paths to flush pending checkpoints. - Redis and memory writes happen immediately.
WithClient(...)WithStore(...)WithGroup(...)WithLogger(...)WithCounter(...)WithShardIteratorType(...)WithTimestamp(...)(used withAT_TIMESTAMPstart behavior)WithScanInterval(...)WithMaxRecords(...)WithGetRecordsOptions(...)WithAggregation(true)to deaggregate KPL records (internal/deaggregator)WithShardClosedHandler(...)
- Retries
GetRecordsloop for:ExpiredIteratorExceptionProvisionedThroughputExceededException
- On retriable errors it rebuilds shard iterator from the last checkpointed sequence.
- Non-retriable errors stop scan and return up.
- Run all tests:
go test ./...
- This repo currently passes tests locally with default setup.
- Example programs are in
examples/:examples/producerexamples/consumerexamples/consumer-redisexamples/consumer-dynamodbexamples/consumer-postgresexamples/consumer-mysql
- Examples target local endpoints by default:
- Kinesis:
http://localhost:4567(typically Kinesalite) - DynamoDB:
http://localhost:8000(for DDB example)
- Kinesis:
- Unit tests cover:
- consumer scan semantics
- shard discovery/ordering logic
- store implementations
- deaggregator behavior
- CI config (
.travis.yml) historically used:- Go 1.13
go test -v -race ./...- Redis service
- If no custom
Storeis supplied, checkpoints are effectively non-persistent. - If no custom
Logger/Counteris supplied, observability is mostly silent. Scanstarts one goroutine per shard; callback should be thread-safe across shards.- For SQL stores, expected schema must exist before running consumer (see
README.mdexamples). ErrSkipCheckpointis supported to continue scanning without failing the consumer callback flow.