-
Notifications
You must be signed in to change notification settings - Fork 23
/
subscribe.go
57 lines (47 loc) · 1.17 KB
/
subscribe.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 main
import (
"fmt"
"strconv"
"time"
"github.com/jhunters/bigqueue"
)
func main() {
var queue = new(bigqueue.FileQueue)
// use custom options
var DefaultOptions = &bigqueue.Options{
DataPageSize: bigqueue.DefaultDataPageSize,
IndexItemsPerPage: bigqueue.DefaultIndexItemsPerPage,
}
// open queue files
err := queue.Open("./bin", "testqueue", DefaultOptions)
if err != nil {
fmt.Println(err)
}
defer queue.Close()
for i := 1; i < 10; i++ {
data := []byte("hello jhunters" + strconv.Itoa(i))
i, err := queue.Enqueue(data)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Enqueued index=", i, string(data))
}
}
queue.Subscribe(func(index int64, bb []byte, err error) {
fmt.Println("index=", index, " value=", string(bb))
})
// for y := 0; y < 10; y++ {
// // do enqueue
// for i := 1; i < 10; i++ {
// data := []byte("hello jhunters" + strconv.Itoa(i))
// i, err := queue.Enqueue(data)
// if err != nil {
// fmt.Println(err)
// } else {
// fmt.Println("Enqueued index=", i, string(data))
// }
// }
// time.Sleep(time.Duration(1) * time.Second)
// }
time.Sleep(time.Duration(10) * time.Second)
}