-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_and_playback.go
81 lines (63 loc) · 1.46 KB
/
storage_and_playback.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"strconv"
pubnub "github.com/pubnub/go"
)
func getAllMessages(startTT int64) {
config := pubnub.NewConfig()
config.SubscribeKey = "demo"
config.PublishKey = "demo"
config.SecretKey = "my-secret"
config.AuthKey = "my-auth"
pn := pubnub.NewPubNub(config)
res, _, _ := pn.History().
Channel("history_channel").
Count(2).
Execute()
msgs := res.Messages
start := res.StartTimetoken
end := res.EndTimetoken
if len(msgs) > 0 {
fmt.Println(len(msgs))
fmt.Println("start " + strconv.Itoa(int(start)))
fmt.Println("end " + strconv.Itoa(int(end)))
}
if len(msgs) == 100 {
getAllMessages(start)
}
}
func main() {
config := pubnub.NewConfig()
config.SubscribeKey = "demo"
config.PublishKey = "demo"
config.SecretKey = "my-secret"
config.AuthKey = "my-auth"
pn := pubnub.NewPubNub(config)
for i := 0; i < 500; i++ {
pn.Publish().
Message("message #" + strconv.Itoa(i)).
Channel("history_channel").
ShouldStore(true).
Execute()
}
res, status, err := pn.History().
Channel("history_channel").
Count(2).
Execute()
fmt.Println(res, status, err)
res, status, err = pn.History().
Channel("history_channel").
Count(100).
Start(13847168620721752).
End(15090358935871532).
Execute()
fmt.Println(res, status, err)
res, status, err = pn.History().
Channel("history_channel").
Count(100).
IncludeTimetoken(true).
Execute()
fmt.Println(res, status, err)
getAllMessages(int64(15090358935871532))
}