forked from didapinchegit/go_rocket_mq
-
Notifications
You must be signed in to change notification settings - Fork 15
/
client_test.go
107 lines (95 loc) · 2.74 KB
/
client_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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package rocketmq
import (
"encoding/json"
"io/ioutil"
"log"
"strings"
"testing"
"time"
)
var ch = make(chan *RemotingCommand)
var client = NewDefaultRemotingClient()
func TestConnect(t *testing.T) {
log.SetFlags(log.Lshortfile | log.LstdFlags)
broker := "192.168.1.197:10911"
namesrv := "192.168.1.234:9876"
data, err := ioutil.ReadFile("request.txt")
if err != nil {
log.Print(err)
}
lines := strings.Split(string(data), "\n")
var lastHeader, lastBody []byte
for _, line := range lines {
if strings.HasPrefix(line, "header=") {
if lastHeader != nil {
cmd := new(RemotingCommand)
cmd.Body = lastBody
err = json.Unmarshal(lastHeader, cmd)
if err != nil {
log.Print(err)
return
}
callback := func(responseFuture *ResponseFuture) {
}
switch cmd.Code {
case 101:
getKvCallback := func(responseFuture *ResponseFuture) {
jsonCmd, _ := json.Marshal(responseFuture.responseCommand)
log.Printf("resp=%s", string(jsonCmd))
}
err := client.invokeAsync(namesrv, cmd, 5000, getKvCallback)
if err != nil {
log.Print(err)
}
case 105:
getRouteInfoCallback := func(responseFuture *ResponseFuture) {
jsonCmd, _ := json.Marshal(responseFuture.responseCommand)
log.Printf("resp=%s", string(jsonCmd))
log.Print(string(responseFuture.responseCommand.Body))
}
err := client.invokeAsync(namesrv, cmd, 5000, getRouteInfoCallback)
if err != nil {
log.Print(err)
}
case 34:
err := client.invokeAsync(broker, cmd, 5000, callback)
if err != nil {
log.Print(err)
}
case 38:
log.Print("getConsumerListCallback")
getConsumerListCallback := func(responseFuture *ResponseFuture) {
jsonCmd, _ := json.Marshal(responseFuture.responseCommand)
log.Printf("getConsumerListCallback=%s", string(jsonCmd))
log.Print(string(responseFuture.responseCommand.Body))
}
log.Print(cmd)
err := client.invokeAsync(broker, cmd, 5000, getConsumerListCallback)
if err != nil {
log.Print(err)
}
case 11:
pullCallback := func(responseFuture *ResponseFuture) {
//if responseFuture.responseCommand.Code == 0 && len(responseFuture.responseCommand.Body) > 0 {
//msgs := decodeMessage(responseFuture.responseCommand.Body)
//for _, msg := range msgs {
//log.Print(string(msg.Body))
//}
//}
}
err := client.invokeAsync(broker, cmd, 5000, pullCallback)
if err != nil {
log.Print(err)
}
}
}
}
if strings.HasPrefix(line, "header=") {
lastHeader = []byte(strings.TrimLeft(line, "header="))
}
if strings.HasPrefix(line, "body=") {
lastBody = []byte(strings.TrimLeft(line, "body="))
}
}
time.Sleep(1000 * time.Second)
}