-
Notifications
You must be signed in to change notification settings - Fork 8
/
doc.go
91 lines (74 loc) · 1.68 KB
/
doc.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
82
83
84
85
86
87
88
89
90
91
/*
Package ami - Go client to reliable queues based on Redis Cluster Streams https://redis.io/topics/streams-intro.
Producer example
type errorLogger struct{}
func (l *errorLogger) AmiError(err error) {
println("Got error from Ami:", err.Error())
}
pr, err := ami.NewProducer(
ami.ProducerOptions{
ErrorNotifier: &errorLogger{},
Name: "ruthie",
PendingBufferSize: 10000000,
PipeBufferSize: 50000,
PipePeriod: time.Microsecond * 1000,
ShardsCount: 10,
},
&redis.ClusterOptions{
Addrs: []string{"172.17.0.1:7001", "172.17.0.1:7002"},
ReadTimeout: time.Second * 60,
WriteTimeout: time.Second * 60,
},
)
if err != nil {
panic(err)
}
for i := 0; i < 10000; i++ {
pr.Send("{}")
}
pr.Close()
Consumer example
type errorLogger struct{}
func (l *errorLogger) AmiError(err error) {
println("Got error from Ami:", err.Error())
}
cn, err := ami.NewConsumer(
ami.ConsumerOptions{
Consumer: "alice",
ErrorNotifier: &errorLogger{},
Name: "ruthie",
PendingBufferSize: 10000000,
PipeBufferSize: 50000,
PipePeriod: time.Microsecond * 1000,
PrefetchCount: 100,
ShardsCount: 10,
},
&redis.ClusterOptions{
Addrs: []string{"172.17.0.1:7001", "172.17.0.1:7002"},
ReadTimeout: time.Second * 60,
WriteTimeout: time.Second * 60,
},
)
if err != nil {
panic(err)
}
c := cn.Start()
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
for {
m, more := <-c
if !more {
break
}
println("Got", m.Body, "ID", m.ID)
cn.Ack(m)
}
wg.Done()
}()
time.Sleep(time.Second)
cn.Stop()
wg.Wait()
cn.Close()
*/
package ami