forked from a8m/kinesis-producer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
50 lines (41 loc) · 843 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
45
46
47
48
49
50
package producer
import (
"context"
"log"
"time"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/kinesis"
)
func ExampleSimple() {
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion("us-west-2"),
)
if err != nil {
// handle error
log.Fatal(err)
}
client := kinesis.NewFromConfig(cfg)
pr := New(&Config{
StreamName: "test",
BacklogCount: 2000,
Client: client,
})
pr.Start()
// Handle failures
go func() {
for r := range pr.NotifyFailures() {
// r contains `Data`, `PartitionKey` and `Error()`
log.Printf("detected put failure, %v", r)
}
}()
go func() {
for i := 0; i < 5000; i++ {
err := pr.Put([]byte("foo"), "bar")
if err != nil {
log.Printf("error producing, %v", err)
}
}
}()
time.Sleep(3 * time.Second)
pr.Stop()
}