As I develop my Mule connector for MQTT, I ran into some issues that kept me from testing real-world scenarios from my Apple laptop and desktop. Anytime I connect using the Eclipse Paho MqttClient class, and subscribe to a given topic, I will inevitably get a “Connection Lost” exception after two to four minutes of time. I mitigate this in my Mule connector by auto-reconnecting to the MQTT broker, however, I was baffled at why this was happening.
I started by running the Sample class provided by the Eclipse Paho team. I pointed this at my local instance of Mosquitto (installed via Homebrew), and subscribed to a topic. I simply let the program run without publishing any messages to the broker. After roughly two minutes, I would get disconnected. Figuring my configuration of Mosquitto was to blame, I pointed this at the public test Mosquitto server, found at test.mosquitto.org. Again, I repeated the same steps with the same results, an exception was generated minutes later for Connection Lost.
Finally, I pointed the Sample class at a different broker all together, which in this case was the dev.rabbitmq.com public broker. Same topic subscription and M.O, I connected and subscribed, and waited. Thirty minutes passed without a single “connection lost” exception. To hopefully prove network issues, I re-pointed the program at test.mosquitto.org, and again found myself getting bounced in a couple minutes.
I’m at a loss for the cause of this issue, other then something with Mac’s implementation of Java and Mosquitto. I even tested this using the Oracle Java7 version for Mac, and found the same issue. Simply changing the broker implementation fixed it, though I can’t believe that’s the issue’s core.
Running this same code against any Mosquitto broker instance from an Ubuntu Server installation has absolutely no issue. I’ve reproduced this issue only on Apple computers, currently an Apple iMac running Lion and an Apple MacBook Pro running Mountain Lion.
Please tell me that someone has had similar issues and knows how to fix them? Or can give me something else to try? I’ve posted the links to the code that I ran to test this below.