|
|
@@ -8,34 +8,49 @@ import (
|
|
8
|
8
|
"net/http"
|
|
9
|
9
|
"testing"
|
|
10
|
10
|
"time"
|
|
|
11
|
+
|
|
|
12
|
+ "git.x2erp.com/qdy/go-base/types"
|
|
11
|
13
|
)
|
|
12
|
14
|
|
|
13
|
|
-type ExchangeRequest struct {
|
|
14
|
|
- ChannelName string `json:"channel_name"`
|
|
15
|
|
- ExchangeName string `json:"exchange_name"`
|
|
16
|
|
- ExchangeType string `json:"exchange_type"`
|
|
17
|
|
- Durable bool `json:"durable"`
|
|
18
|
|
- Internal bool `json:"internal"`
|
|
19
|
|
- AutoDelete bool `json:"auto_delete"`
|
|
20
|
|
- NoWait bool `json:"no_wait"`
|
|
21
|
|
- Arguments map[string]string `json:"arguments"`
|
|
22
|
|
-}
|
|
|
15
|
+// type ExchangeRequest struct {
|
|
|
16
|
+// ChannelName string `json:"channel_name"`
|
|
|
17
|
+// ExchangeName string `json:"exchange_name"`
|
|
|
18
|
+// ExchangeType string `json:"exchange_type"`
|
|
|
19
|
+// Durable bool `json:"durable"`
|
|
|
20
|
+// Internal bool `json:"internal"`
|
|
|
21
|
+// AutoDelete bool `json:"auto_delete"`
|
|
|
22
|
+// NoWait bool `json:"no_wait"`
|
|
|
23
|
+// Arguments map[string]string `json:"arguments"`
|
|
|
24
|
+// }
|
|
23
|
25
|
|
|
24
|
26
|
func TestCreateexchange(t *testing.T) {
|
|
25
|
27
|
// 1. 准备请求数据
|
|
26
|
|
- requestData := ExchangeRequest{
|
|
27
|
|
- ChannelName: "test_channel",
|
|
28
|
|
- ExchangeName: "test_exchange",
|
|
29
|
|
- ExchangeType: "direct", // direct, fanout, topic, headers
|
|
|
28
|
+ requestData := types.ExchangeRequest{
|
|
|
29
|
+ ChannelName: "v_bdx_channel",
|
|
|
30
|
+ ExchangeName: "v_bdx_exchange",
|
|
|
31
|
+ ExchangeType: "topic", // direct, fanout, topic, headers
|
|
30
|
32
|
Durable: true,
|
|
31
|
33
|
Internal: false,
|
|
32
|
34
|
AutoDelete: false,
|
|
33
|
35
|
NoWait: false,
|
|
34
|
36
|
Arguments: map[string]string{
|
|
35
|
|
- "x-delayed-type": "direct",
|
|
|
37
|
+ "x-delayed-type": "topic",
|
|
36
|
38
|
},
|
|
37
|
39
|
}
|
|
38
|
40
|
|
|
|
41
|
+ // 消息队列
|
|
|
42
|
+ queueRequest := types.QueueRequest{
|
|
|
43
|
+ QueueName: "vbdx_queue_count",
|
|
|
44
|
+ ChannelName: requestData.ChannelName,
|
|
|
45
|
+ }
|
|
|
46
|
+
|
|
|
47
|
+ queueBindRequest := types.QueueBindRequest{
|
|
|
48
|
+ ChannelName: requestData.ChannelName,
|
|
|
49
|
+ QueueName: queueRequest.QueueName,
|
|
|
50
|
+ ExchangeName: requestData.ExchangeName,
|
|
|
51
|
+ RoutingKey: "v-bdx.#",
|
|
|
52
|
+ }
|
|
|
53
|
+
|
|
39
|
54
|
// 2. 将数据转换为JSON
|
|
40
|
55
|
jsonData, err := json.Marshal(requestData)
|
|
41
|
56
|
if err != nil {
|
|
|
@@ -46,8 +61,47 @@ func TestCreateexchange(t *testing.T) {
|
|
46
|
61
|
// 3. 发送HTTP POST请求
|
|
47
|
62
|
url := "http://localhost:9090/api/rabbitmq/exchange/create"
|
|
48
|
63
|
|
|
|
64
|
+ POST(jsonData, url)
|
|
|
65
|
+
|
|
|
66
|
+ //建立队列
|
|
|
67
|
+ CreateQueue(queueRequest)
|
|
|
68
|
+
|
|
|
69
|
+ //绑定
|
|
|
70
|
+ CreateQueueBind(queueBindRequest)
|
|
|
71
|
+}
|
|
|
72
|
+
|
|
|
73
|
+func CreateQueue(queueRequest types.QueueRequest) {
|
|
|
74
|
+
|
|
|
75
|
+ // 2. 将数据转换为JSON
|
|
|
76
|
+ jsonData, err := json.Marshal(queueRequest)
|
|
|
77
|
+ if err != nil {
|
|
|
78
|
+ fmt.Printf("JSON编码失败: %v\n", err)
|
|
|
79
|
+ return
|
|
|
80
|
+ }
|
|
|
81
|
+ url := "http://localhost:9090/api/rabbitmq/queue/create"
|
|
|
82
|
+
|
|
|
83
|
+ POST(jsonData, url)
|
|
|
84
|
+
|
|
|
85
|
+}
|
|
|
86
|
+
|
|
|
87
|
+func CreateQueueBind(queueBindRequest types.QueueBindRequest) {
|
|
|
88
|
+
|
|
|
89
|
+ // 2. 将数据转换为JSON
|
|
|
90
|
+ jsonData, err := json.Marshal(queueBindRequest)
|
|
|
91
|
+ if err != nil {
|
|
|
92
|
+ fmt.Printf("JSON编码失败: %v\n", err)
|
|
|
93
|
+ return
|
|
|
94
|
+ }
|
|
|
95
|
+ url := "http://localhost:9090/api/rabbitmq/queue/bind"
|
|
|
96
|
+
|
|
|
97
|
+ POST(jsonData, url)
|
|
|
98
|
+
|
|
|
99
|
+}
|
|
|
100
|
+
|
|
|
101
|
+func POST(jsonData []byte, url string) {
|
|
|
102
|
+
|
|
49
|
103
|
// 如果服务端需要认证,添加JWT token
|
|
50
|
|
- token := "your-jwt-token-here" // 替换为实际的JWT token
|
|
|
104
|
+ token := "123" // 替换为实际的JWT token
|
|
51
|
105
|
|
|
52
|
106
|
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
|
|
53
|
107
|
if err != nil {
|