diff --git a/src/udi/dispatcher/dispatcher.go b/src/udi/dispatcher/dispatcher.go index 6cdee10..f543bf8 100644 --- a/src/udi/dispatcher/dispatcher.go +++ b/src/udi/dispatcher/dispatcher.go @@ -27,7 +27,7 @@ func InputDispatcher() { for { select { case message := <- mqtt.InputChannel: - log.Printf("Message arrived in inputDispatcher, topic: %s, payload: %s\n", message.Topic, message.Payload) + log.Printf("Message arrived in inputDispatcher, topic: %s\n", message.Topic) for _, mapping := range config.Config.TopicMappings { log.Printf("Testing %s -> %s", mapping.Topics, mapping.Handler) @@ -35,8 +35,12 @@ func InputDispatcher() { 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 := handlerMap[mapping.Handler] - handler.Handle(message.Topic, string(message.Payload)) + handler, exists := handlerMap[mapping.Handler] + if exists { + handler.Handle(message.Topic, string(message.Payload)) + } else { + log.Printf("Handler not found, message is lost") + } } else { log.Printf("no match") }