-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexample_checkpoint_test.go
59 lines (49 loc) · 1.5 KB
/
example_checkpoint_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
58
59
package gokini
import (
"fmt"
"time"
)
type CheckpointRecordConsumer struct {
shardID string
}
func (p *CheckpointRecordConsumer) Init(shardID string) error {
fmt.Printf("Checkpointer initializing\n")
p.shardID = shardID
return nil
}
func (p *CheckpointRecordConsumer) ProcessRecords(records []*Records, consumer *KinesisConsumer) {
if len(records) > 0 {
fmt.Printf("%s\n", records[0].Data)
}
consumer.Checkpoint(p.shardID, records[len(records)-1].SequenceNumber)
}
func (p *CheckpointRecordConsumer) Shutdown() {
fmt.Print("PrintRecordConsumer Shutdown\n")
}
func ExampleCheckpointRecordConsumer() {
// An implementation of the RecordConsumer interface that prints out records and checkpoints at the end
rc := &PrintRecordConsumer{}
kc := &KinesisConsumer{
StreamName: "KINESIS_STREAM_2",
ShardIteratorType: "TRIM_HORIZON",
RecordConsumer: rc,
TableName: "gokini_2",
EmptyRecordBackoffMs: 1000,
}
// Send records to our kinesis stream so we have something to process
pushRecordToKinesis("KINESIS_STREAM_2", []byte("example_checkpoint_record_consumer"), true)
defer deleteStream("KINESIS_STREAM_2")
defer deleteTable("gokini_2")
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()
time.Sleep(200 * time.Millisecond)
// Output:
// Checkpointer initializing
// example_checkpoint_record_consumer
// PrintRecordConsumer Shutdown
}