Subscribing MQTT using Goroutine not printing messages
Subscribing MQTT using Goroutine not printing messages I currently have Go code that subscribes to a topic and prints out sensor data. The part that prints out the sensor data is in a Goroutine , however, nothing is printing out currently. This is my code: package main import ( "fmt" MQTT "github.com/eclipse/paho.mqtt.golang" "os" "os/signal" "syscall" "sync" ) var wg sync.WaitGroup func subscriber(client MQTT.Client, message MQTT.Message) { wg.Add(1) go func() { defer wg.Done() fmt.Printf("%sn", message.Payload()) }() } func main() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) opts := MQTT.NewClientOptions().AddBroker("tcp://test.mosquitto.org:1883") //opts.SetDefaultPublishHandler(f) // Topic to subscribe to for sensor data topic := "sensor/data" client := MQTT.NewClient(opts) if ...
