-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstream_test.go
48 lines (46 loc) · 1.16 KB
/
stream_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
package rmq
import (
"context"
"fmt"
"github.com/go-redis/redis/v8"
"strconv"
"sync"
"testing"
)
func TestNewStreamMQ(t *testing.T) {
client := redis.NewClient(&redis.Options{
Addr: "127.0.0.1:6379",
})
q := NewStreamMQ(client, 100, true)
topic := "test"
count := 10
var wg sync.WaitGroup
wg.Add(count * 4)
go q.Consume(context.Background(), topic, "group1", "consumer1", "$", 5, func(msg *Msg) error {
fmt.Printf("consume group1 consumer1: %+v\n", msg)
wg.Done()
return nil
})
go q.Consume(context.Background(), topic, "group1", "consumer2", "$", 5, func(msg *Msg) error {
fmt.Printf("consume group1 consumer2: %+v\n", msg)
wg.Done()
return nil
})
go q.Consume(context.Background(), topic, "group2", "consumer1", "$", 5, func(msg *Msg) error {
fmt.Printf("consume group2 consumer1: %+v\n", msg)
wg.Done()
return nil
})
go q.Consume(context.Background(), topic, "group2", "consumer2", "$", 5, func(msg *Msg) error {
fmt.Printf("consume group2 consumer2: %+v\n", msg)
wg.Done()
return nil
})
for i := 0; i < count; i++ {
q.SendMsg(context.Background(), &Msg{
Topic: topic,
Body: []byte(topic + strconv.Itoa(i)),
})
}
wg.Wait()
}