forked from a8m/kinesis-producer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
44 lines (37 loc) · 824 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package producer
import (
"log"
"os"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/kinesis"
)
func ExampleSimple() {
logger := &StdLogger{log.New(os.Stdout, "", log.LstdFlags)}
client := kinesis.New(session.New(aws.NewConfig()))
pr := New(&Config{
StreamName: "test",
BacklogCount: 2000,
Client: client,
Logger: logger,
})
pr.Start()
// Handle failures
go func() {
for r := range pr.NotifyFailures() {
// r contains `Data`, `PartitionKey` and `Error()`
logger.Error("detected put failure", r.error)
}
}()
go func() {
for i := 0; i < 5000; i++ {
err := pr.Put([]byte("foo"), "bar")
if err != nil {
logger.Error("error producing", err)
}
}
}()
time.Sleep(3 * time.Second)
pr.Stop()
}