-
Notifications
You must be signed in to change notification settings - Fork 51
/
example_test.go
45 lines (38 loc) · 840 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
package producer
import (
"context"
"log"
"os"
"time"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/kinesis"
)
func ExampleSimple() {
logger := &StdLogger{log.New(os.Stdout, "", log.LstdFlags)}
cfg, _ := config.LoadDefaultConfig(context.TODO())
client := kinesis.NewFromConfig(cfg)
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()
}