kinesis-consumer/README.md

114 lines
3.3 KiB
Markdown
Raw Normal View History

# Golang Kinesis Connectors
2015-05-23 23:18:10 +00:00
__Kinesis connector applications written in Go__
2016-02-09 03:41:36 +00:00
> With the new release of Kinesis Firehose I'd recommend using the [Lambda Streams to Firehose](https://github.com/awslabs/lambda-streams-to-firehose) project for loading data directly into S3 and Redshift.
2016-02-09 03:41:36 +00:00
Inspired by the [Amazon Kinesis Connector Library](https://github.com/awslabs/amazon-kinesis-connectors). 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.
2015-05-23 23:18:10 +00:00
![golang_kinesis_connector](https://cloud.githubusercontent.com/assets/739782/4262283/2ee2550e-3b97-11e4-8cd1-21a5d7ee0964.png)
## Overview
The consumer expects a handler func that will process a buffer of incoming records.
```go
func main() {
var(
2016-05-08 01:15:55 +00:00
app = flag.String("app", "", "The app name")
stream = flag.String("stream", "", "The stream name")
)
flag.Parse()
// create new consumer
2016-05-08 01:15:55 +00:00
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
2016-05-08 01:15:55 +00:00
[Apex Log](https://medium.com/@tjholowaychuk/apex-log-e8d9627f4a9a#.5x1uo1767) is used for logging Info. Override the logs format with other [Log Handlers](https://github.com/apex/log/tree/master/_examples). For example using the "json" log handler:
```go
import(
2016-05-08 01:15:55 +00:00
"github.com/apex/log"
"github.com/apex/log/handlers/json"
)
func main() {
// ...
2016-05-08 01:15:55 +00:00
log.SetHandler(json.New(os.Stderr))
log.SetLevel(log.DebugLevel)
}
```
2016-05-01 19:40:30 +00:00
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
```
2015-05-23 20:57:52 +00:00
### Installation
Get the package source:
$ go get github.com/harlow/kinesis-connectors
2016-02-10 07:39:57 +00:00
### Fetching Dependencies
Install `govendor`:
2016-02-10 07:39:57 +00:00
$ export GO15VENDOREXPERIMENT=1
$ go get -u github.com/kardianos/govendor
2016-02-10 07:39:57 +00:00
Install dependencies into `./vendor/`:
$ govendor sync
2016-02-10 07:39:57 +00:00
2016-02-09 03:39:09 +00:00
### Examples
2015-05-23 23:10:08 +00:00
2016-02-09 03:39:09 +00:00
Use the [seed stream](https://github.com/harlow/kinesis-connectors/tree/master/examples/seed) code to put sample data onto the stream.
2015-05-23 23:10:08 +00:00
2016-02-09 03:39:09 +00:00
* [Firehose](https://github.com/harlow/kinesis-connectors/tree/master/examples/firehose)
* [S3](https://github.com/harlow/kinesis-connectors/tree/master/examples/s3)
2015-05-23 23:10:08 +00:00
2015-05-23 23:18:10 +00:00
## Contributing
Please see [CONTRIBUTING.md] for more information. Thank you, [contributors]!
[LICENSE]: /MIT-LICENSE
[CONTRIBUTING.md]: /CONTRIBUTING.md
2015-05-23 23:18:10 +00:00
## License
Copyright (c) 2015 Harlow Ward. It is free software, and may
be redistributed under the terms specified in the [LICENSE] file.
[contributors]: https://github.com/harlow/kinesis-connectors/graphs/contributors
2016-05-01 19:45:27 +00:00
> [www.hward.com](http://www.hward.com)  · 
> GitHub [@harlow](https://github.com/harlow)  · 
> Twitter [@harlow_ward](https://twitter.com/harlow_ward)