-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestMessageGenerator.go
40 lines (35 loc) · 1011 Bytes
/
testMessageGenerator.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
package main
import (
"encoding/json"
"fmt"
"math/rand"
)
func generateTestMessages(n int) []Message {
messages := make([]Message, n)
for i := range messages {
id := rand.Int63()
contentType := "application/json"
correlationID := fmt.Sprintf("correlation-id-%d", id)
// Per Azure Service Bus documentation, is an application-controlled value that should be unique.
messageID := fmt.Sprintf("message-id-%d", id)
subject := fmt.Sprintf("subject-%d", id)
appProperties := map[string]interface{}{
"key1": fmt.Sprintf("value%d", id),
"key2": id,
}
bodydata := map[string]interface{}{
"id": rand.Intn(100),
"name": fmt.Sprintf("name-%d", rand.Intn(100)),
}
body, _ := json.Marshal(bodydata)
messages[i] = Message{
ApplicationProperties: appProperties,
Body: body,
ContentType: &contentType,
CorrelationID: &correlationID,
MessageID: &messageID,
Subject: &subject,
}
}
return messages
}