-
Notifications
You must be signed in to change notification settings - Fork 2
/
topics.go
66 lines (54 loc) · 1.49 KB
/
topics.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
package edgex
import (
"strings"
)
//
// Author: 陈哈哈 [email protected]
//
const (
prefixProperties = "$EdgeX/properties/"
prefixEvents = "$EdgeX/events/"
prefixValues = "$EdgeX/values/"
prefixStates = "$EdgeX/states/"
prefixActions = "$EdgeX/actions/"
prefixStatistics = "$EdgeX/statistics/"
prefixRequests = "$EdgeX/requests/"
prefixReplies = "$EdgeX/replies/"
)
func TopicOfEvents(exTopic string) string {
checkTopicAllowed(exTopic)
return prefixEvents + exTopic
}
func TopicOfValues(exTopic string) string {
checkTopicAllowed(exTopic)
return prefixValues + exTopic
}
func TopicOfStates(nodeId string) string {
checkTopicAllowed(nodeId)
return prefixStates + nodeId
}
func TopicOfActions(nodeId string) string {
checkTopicAllowed(nodeId)
return prefixActions + nodeId
}
func TopicOfProperties(nodeId string) string {
checkTopicAllowed(nodeId)
return prefixProperties + nodeId
}
func topicToRequestCaller(exTopic string) string {
// prefix / ExecutorNodeId / CallerNodeId
idx := strings.LastIndex(exTopic, "/")
return exTopic[idx+1:]
}
func topicOfRequestListen(callerNodeId string) string {
return prefixRequests + callerNodeId + "/+"
}
func topicOfRepliesSend(executorNodeId, callerNodeId string) string {
// prefix / CallerNodeId / ExecutorNodeId
return prefixReplies + callerNodeId + "/" + executorNodeId
}
func checkTopicAllowed(topic string) {
if strings.HasPrefix(topic, "/") {
log.Panicf("Topic MUST NOT starts with '/', was: %s", topic)
}
}