-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexample_test.go
57 lines (47 loc) · 1.26 KB
/
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
51
52
53
54
55
56
57
package gokini
import (
"fmt"
"time"
)
type PrintRecordConsumer struct {
shardID string
}
func (p *PrintRecordConsumer) Init(shardID string) error {
fmt.Printf("Checkpointer initializing\n")
p.shardID = shardID
return nil
}
func (p *PrintRecordConsumer) ProcessRecords(records []*Records, consumer *KinesisConsumer) {
if len(records) > 0 {
fmt.Printf("%s\n", records[0].Data)
}
}
func (p *PrintRecordConsumer) Shutdown() {
fmt.Print("PrintRecordConsumer Shutdown\n")
}
func ExampleRecordConsumer() {
// An implementation of the RecordConsumer interface that prints out records
rc := &PrintRecordConsumer{}
kc := &KinesisConsumer{
StreamName: "KINESIS_STREAM",
ShardIteratorType: "TRIM_HORIZON",
RecordConsumer: rc,
TableName: "gokini",
EmptyRecordBackoffMs: 1000,
}
// Send records to our kinesis stream so we have something to process
pushRecordToKinesis("KINESIS_STREAM", []byte("foo"), true)
defer deleteStream("KINESIS_STREAM")
defer deleteTable("gokini")
err := kc.StartConsumer()
if err != nil {
fmt.Printf("Failed to start consumer: %s", err)
}
// Wait for it to do it's thing
time.Sleep(200 * time.Millisecond)
kc.Shutdown()
// Output:
// Checkpointer initializing
// foo
// PrintRecordConsumer Shutdown
}