2016-05-01 23:54:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"flag"
|
2017-11-20 16:21:40 +00:00
|
|
|
"fmt"
|
2016-05-01 23:54:47 +00:00
|
|
|
"os"
|
2017-11-20 16:21:40 +00:00
|
|
|
"time"
|
2016-05-01 23:54:47 +00:00
|
|
|
|
|
|
|
|
"github.com/apex/log"
|
|
|
|
|
"github.com/apex/log/handlers/text"
|
2017-11-20 16:21:40 +00:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
2016-05-01 23:54:47 +00:00
|
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
|
|
|
|
"github.com/aws/aws-sdk-go/service/kinesis"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
log.SetHandler(text.New(os.Stderr))
|
2016-05-08 01:05:52 +00:00
|
|
|
log.SetLevel(log.DebugLevel)
|
2016-05-01 23:54:47 +00:00
|
|
|
|
2017-11-21 16:58:16 +00:00
|
|
|
var streamName = flag.String("stream", "", "Stream name")
|
2017-11-20 16:21:40 +00:00
|
|
|
flag.Parse()
|
2016-05-01 23:54:47 +00:00
|
|
|
|
2017-11-20 16:21:40 +00:00
|
|
|
// download file with test data
|
|
|
|
|
// curl https://s3.amazonaws.com/kinesis.test/users.txt -o /tmp/users.txt
|
2016-05-01 23:54:47 +00:00
|
|
|
f, err := os.Open("/tmp/users.txt")
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal("Cannot open users.txt file")
|
|
|
|
|
}
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
2017-11-20 16:21:40 +00:00
|
|
|
var (
|
|
|
|
|
svc = kinesis.New(session.New())
|
|
|
|
|
records []*kinesis.PutRecordsRequestEntry
|
|
|
|
|
)
|
|
|
|
|
|
2016-05-01 23:54:47 +00:00
|
|
|
// loop over file data
|
|
|
|
|
b := bufio.NewScanner(f)
|
|
|
|
|
for b.Scan() {
|
2017-11-20 16:21:40 +00:00
|
|
|
records = append(records, &kinesis.PutRecordsRequestEntry{
|
|
|
|
|
Data: b.Bytes(),
|
|
|
|
|
PartitionKey: aws.String(time.Now().Format(time.RFC3339Nano)),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if len(records) > 50 {
|
|
|
|
|
_, err = svc.PutRecords(&kinesis.PutRecordsInput{
|
|
|
|
|
StreamName: streamName,
|
|
|
|
|
Records: records,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.WithError(err).Fatal("error producing")
|
|
|
|
|
}
|
|
|
|
|
records = nil
|
2016-05-01 23:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-20 16:21:40 +00:00
|
|
|
fmt.Print(".")
|
|
|
|
|
}
|
2016-05-01 23:54:47 +00:00
|
|
|
}
|