Skip to content

Commit 493ad5a

Browse files
authored
Merge pull request #4 from inovex/improve_mqtt_client_id
make it easier to identify MQTT client IDs and topic name
2 parents caa41b5 + 244f39e commit 493ad5a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ var (
2121
tearDownInProgress = false
2222
randomSource = rand.New(rand.NewSource(time.Now().UnixNano()))
2323

24-
subscriberClientIdTemplate = "test-client-s-%d-%d"
25-
publisherClientIdTemplate = "test-client-p-%d-%d"
26-
topicNameTemplate = "internal/monitoring/endToEndXx-%d-%d"
24+
subscriberClientIdTemplate = "mqtt-stresser-sub-%s-worker%d-%d"
25+
publisherClientIdTemplate = "mqtt-stresser-pub-%s-worker%d-%d"
26+
topicNameTemplate = "internal/mqtt-stresser/%s/worker%d-%d"
2727

2828
opTimeout = 5 * time.Second
2929

worker.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ func (w *Worker) Run() {
1414
cid := w.WorkerId
1515
t := randomSource.Int31()
1616

17-
topicName := fmt.Sprintf(topicNameTemplate, w.WorkerId, t)
18-
subscriberClientId := fmt.Sprintf(subscriberClientIdTemplate, w.WorkerId, t)
19-
publisherClientId := fmt.Sprintf(publisherClientIdTemplate, w.WorkerId, t)
17+
hostname, err := os.Hostname()
18+
if err != nil {
19+
panic(err)
20+
}
21+
22+
topicName := fmt.Sprintf(topicNameTemplate, hostname, w.WorkerId, t)
23+
subscriberClientId := fmt.Sprintf(subscriberClientIdTemplate, hostname, w.WorkerId, t,)
24+
publisherClientId := fmt.Sprintf(publisherClientIdTemplate, hostname, w.WorkerId, t)
2025

2126
verboseLogger.Printf("[%d] topic=%s subscriberClientId=%s publisherClientId=%s\n", cid, topicName, subscriberClientId, publisherClientId)
2227

0 commit comments

Comments
 (0)