This commit is contained in:
2023-12-04 13:56:39 +01:00
parent ac4d42620a
commit 8e0418791d

View File

@ -72,7 +72,12 @@ func InputDispatcher() {
log.Printf("Message arrived in inputDispatcher, topic: %s\n", mqttMessage.Topic) log.Printf("Message arrived in inputDispatcher, topic: %s\n", mqttMessage.Topic)
message := handler.MessageT { time.Now(), mqttMessage.Topic, string(mqttMessage.Payload) } message := handler.MessageT { time.Now(), mqttMessage.Topic, string(mqttMessage.Payload) }
archiverChannel <- message archiverChannel <- message
handleMessage(message)
}
}
}
func handleMessage(message handler.MessageT) {
for _, mapping := range config.Config.TopicMappings { for _, mapping := range config.Config.TopicMappings {
log.Printf("Testing %s -> %s", mapping.Topics, mapping.Handler) log.Printf("Testing %s -> %s", mapping.Topics, mapping.Handler)
for _, subscribedTopic := range mapping.Topics { for _, subscribedTopic := range mapping.Topics {
@ -82,6 +87,7 @@ func InputDispatcher() {
handler, exists := handlerMap[mapping.Handler] handler, exists := handlerMap[mapping.Handler]
if exists { if exists {
handler.Handle(message) handler.Handle(message)
return
} else { } else {
log.Printf("Handler not found, message is lost") log.Printf("Handler not found, message is lost")
} }
@ -90,6 +96,4 @@ func InputDispatcher() {
} }
} }
} }
}
}
} }