optimize
This commit is contained in:
@ -72,23 +72,27 @@ func InputDispatcher() {
|
||||
log.Printf("Message arrived in inputDispatcher, topic: %s\n", mqttMessage.Topic)
|
||||
message := handler.MessageT { time.Now(), mqttMessage.Topic, string(mqttMessage.Payload) }
|
||||
archiverChannel <- message
|
||||
handleMessage(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, mapping := range config.Config.TopicMappings {
|
||||
log.Printf("Testing %s -> %s", mapping.Topics, mapping.Handler)
|
||||
for _, subscribedTopic := range mapping.Topics {
|
||||
log.Printf("Testing %s in %s", message.Topic, subscribedTopic)
|
||||
if mqtt.TopicMatchesSubscription(message.Topic, subscribedTopic) {
|
||||
log.Printf("Handle message in handler %s", mapping.Handler)
|
||||
handler, exists := handlerMap[mapping.Handler]
|
||||
if exists {
|
||||
handler.Handle(message)
|
||||
} else {
|
||||
log.Printf("Handler not found, message is lost")
|
||||
}
|
||||
} else {
|
||||
log.Printf("no match")
|
||||
}
|
||||
func handleMessage(message handler.MessageT) {
|
||||
for _, mapping := range config.Config.TopicMappings {
|
||||
log.Printf("Testing %s -> %s", mapping.Topics, mapping.Handler)
|
||||
for _, subscribedTopic := range mapping.Topics {
|
||||
log.Printf("Testing %s in %s", message.Topic, subscribedTopic)
|
||||
if mqtt.TopicMatchesSubscription(message.Topic, subscribedTopic) {
|
||||
log.Printf("Handle message in handler %s", mapping.Handler)
|
||||
handler, exists := handlerMap[mapping.Handler]
|
||||
if exists {
|
||||
handler.Handle(message)
|
||||
return
|
||||
} else {
|
||||
log.Printf("Handler not found, message is lost")
|
||||
}
|
||||
} else {
|
||||
log.Printf("no match")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user