0

I have a client that has created a session with my MQTT server (RabbitMQ) using cleansession=true and subscribed to a topic. When I changed my code to have cleansession=false and restarted the client, it is having issues with not being able to connect (on Golang using Paho). However, when I create a new session with a different clientId, things work. I can recreate this and the error is only when I try to change the cleansession value for a clientId.

I have not seen anything on the MQTT documentation saying that a client cannot change their cleanState value during subsequent connections. Is there such a problem?

My client code: package main

import (
    "fmt"
    mqtt "git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git"
)

var mqttFunc mqtt.MessageHandler = func(client *mqtt.Client, msg mqtt.Message)       {
    fmt.Printf("Topic: %s\n", msg.Topic())
    fmt.Printf("Msg: %s\n", msg.Payload())
}

func main() {
    opts := mqtt.NewClientOptions().AddBroker("tcp://localhost:1883/")
    opts.SetClientID("clientE")
    opts.SetDefaultPublishHandler(mqttFunc)

    // This is the line I change
    opts.SetCleanSession(false)

    c := mqtt.NewClient(opts)
    token := c.Connect()
    if token.Wait() && token.Error() != nil {
        panic(token.Error())
    }

    token = c.Subscribe("together/example1", 1, nil)
    if token.Wait() && token.Error() != nil {
        fmt.Println(token.Error())
        panic(1)
    }

    forever := make(chan bool)
    <-forever
}

Error when running the client:

panic: Network Error : %!s(<nil>)

goroutine 16 [running]:
runtime.panic(0x28b700, 0xc208000dc0)
/usr/local/go/src/pkg/runtime/panic.c:279 +0xf5
main.main()
/Users/Foo/Work/Go/src/github.com/bar/rabbitmq/tutorial/mqtt_receiver.go:23 +0x149

goroutine 19 [finalizer wait]:
runtime.park(0x14bb0, 0x4910d0, 0x48fbc9)
/usr/local/go/src/pkg/runtime/proc.c:1369 +0x89
runtime.parkunlock(0x4910d0, 0x48fbc9)
/usr/local/go/src/pkg/runtime/proc.c:1385 +0x3b
runfinq()
/usr/local/go/src/pkg/runtime/mgc0.c:2644 +0xcf
runtime.goexit()
/usr/local/go/src/pkg/runtime/proc.c:1445

goroutine 17 [syscall]:
runtime.goexit()
/usr/local/go/src/pkg/runtime/proc.c:1445
exit status 2
wislo
  • 1,110
  • 2
  • 13
  • 24
  • 1
    Have you tried this against a different broker, e.g. test.mosquitto.org to see whether it is a problem with rabbitmq or the client code? – ralight Dec 02 '15 at 15:33
  • @ralight good point. it works fine with test.mosquitto.org. So it seems like an RabbitMQ issue or I have misconfigured my broker. – wislo Dec 03 '15 at 09:11

0 Answers0