Currently writing a Java application to publish/subscribe to the Internet of Things MQTT server using the Eclipse Paho Lib (org.eclipse.paho.client.mqtt3-1.0.2.jar), both on Device and Application side.
Connect works well with both credential types, and the same seems to be the publish... What gives me the error is the subscribe:
Trying it by mosquitto_sub command line, it looks like this.
Client a:u5o0ux:tws sending CONNECT
Client a:u5o0ux:tws received CONNACK
Client a:u5o0ux:tws sending SUBSCRIBE (Mid: 1, Topic: matteo, QoS: 0)
Client a:u5o0ux:tws sending CONNECT
Client a:u5o0ux:tws received CONNACK
Client a:u5o0ux:tws sending SUBSCRIBE (Mid: 2, Topic: matteo, QoS: 0)
Client a:u5o0ux:tws sending CONNECT
Client a:u5o0ux:tws received CONNACK
Client a:u5o0ux:tws sending SUBSCRIBE (Mid: 3, Topic: matteo, QoS: 0)
Client a:u5o0ux:tws sending CONNECT
Client a:u5o0ux:tws received CONNACK
Client a:u5o0ux:tws sending SUBSCRIBE (Mid: 4, Topic: matteo, QoS: 0)
...
and so on.
When I try with java with a MqttAsyncClient, the subcribe() method returns, but then the waitForCompletion() method instantly follows.
Connection lost (32109) - java.io.EOFException
My code goes like this.
String tmpDir = System.getProperty("java.io.tmpdir");
MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir);
...
// Construct a non blocking MQTT client instance
client = new MqttAsyncClient(getMQTTBrokerURL(), clientId, dataStore);
// Set this wrapper as the callback handler
client.setCallback(this);
and then:
connect();
...
IMqttToken subToken = client.subscribe(topic, qos, null, null);
subToken.waitForCompletion();
Also, this error makes sure that the lib does not release the persistence path used by the AsyncClient, making it trow a "Persistence Already in Use" exception on every retry until I stop the JVM and manually clear that path, but I suppose this to be some sort of library bug.
Unfortunately, I don't know how to access the IoT-side mqtt server to realize what's going on in there.
Any ideas?