Golang library for consuming Kinesis stream data
Find a file
Pierre Massat c04f3d8a94 Get a new shard iterator on error (#32)
* Get a new shard iterator on error
* Check for nil instead of empty string
* Get a new shard iterator on error
2017-10-15 17:40:30 -07:00
emitter Update S3 emitter initialization 2016-05-01 15:07:58 -07:00
examples Add required fields to Config 2016-05-07 18:10:31 -07:00
vendor Add checkpoint interface for custom checkpoints (#29) 2016-12-04 00:08:06 -08:00
.gitignore Add checkpoint interface for custom checkpoints (#29) 2016-12-04 00:08:06 -08:00
buffer.go Expose the shard ID in the buffer (#30) 2016-12-26 08:24:34 -07:00
buffer_test.go Add required fields to Config 2016-05-07 18:10:31 -07:00
checkpoint.go Add checkpoint interface for custom checkpoints (#29) 2016-12-04 00:08:06 -08:00
config.go Add checkpoint interface for custom checkpoints (#29) 2016-12-04 00:08:06 -08:00
consumer.go Get a new shard iterator on error (#32) 2017-10-15 17:40:30 -07:00
CONTRIBUTING.md Rename License file and add Contributing sections 2015-05-23 10:24:53 -07:00
handler.go Refactor to use handler func 2016-02-06 17:50:17 -08:00
MIT-LICENSE Rename License file and add Contributing sections 2015-05-23 10:24:53 -07:00
README.md Add checkpoint interface for custom checkpoints (#29) 2016-12-04 00:08:06 -08:00
redis_checkpoint.go Add checkpoint interface for custom checkpoints (#29) 2016-12-04 00:08:06 -08:00
redis_checkpoint_test.go Add checkpoint interface for custom checkpoints (#29) 2016-12-04 00:08:06 -08:00

Golang Kinesis Connectors

Kinesis connector applications written in Go

With the new release of Kinesis Firehose I'd recommend using the Lambda Streams to Firehose project for loading data directly into S3 and Redshift.

Inspired by the Amazon Kinesis Connector Library. This library is intended to be a lightweight wrapper around the Kinesis API to handle batching records, setting checkpoints, respecting ratelimits, and recovering from network errors.

golang_kinesis_connector

Overview

The consumer expects a handler func that will process a buffer of incoming records.

func main() {
  var(
    app    = flag.String("app", "", "The app name")
    stream = flag.String("stream", "", "The stream name")
  )
  flag.Parse()

  // create new consumer
  c := connector.NewConsumer(connector.Config{
    AppName:        *app,
    MaxRecordCount: 400,
    Streamname:     *stream,
  })

  // process records from the stream
  c.Start(connector.HandlerFunc(func(b connector.Buffer) {
    fmt.Println(b.GetRecords())
  }))

  select {}
}

Config

The default behavior for checkpointing uses Redis on localhost. To set a custom Redis URL use ENV vars:

REDIS_URL=my-custom-redis-server.com:6379

Logging

Apex Log is used for logging Info. Override the logs format with other Log Handlers. For example using the "json" log handler:

import(
  "github.com/apex/log"
  "github.com/apex/log/handlers/json"
)

func main() {
  // ...

  log.SetHandler(json.New(os.Stderr))
  log.SetLevel(log.DebugLevel)
}

Which will producde the following logs:

  INFO[0000] processing                app=test shard=shardId-000000000000 stream=test
  INFO[0008] emitted                   app=test count=500 shard=shardId-000000000000 stream=test
  INFO[0012] emitted                   app=test count=500 shard=shardId-000000000000 stream=test

Installation

Get the package source:

$ go get github.com/harlow/kinesis-connectors

Fetching Dependencies

Install govendor:

$ export GO15VENDOREXPERIMENT=1
$ go get -u github.com/kardianos/govendor

Install dependencies into ./vendor/:

$ govendor sync

Examples

Use the seed stream code to put sample data onto the stream.

Contributing

Please see CONTRIBUTING.md for more information. Thank you, contributors!

License

Copyright (c) 2015 Harlow Ward. It is free software, and may be redistributed under the terms specified in the LICENSE file.

www.hward.com  ·  GitHub @harlow  ·  Twitter @harlow_ward