IAMSKU
IAMSKU

Reputation: 33

Error while subscribing with paho MQTT broker

I am facing error while subscribing to MQTT broker (org.eclipse.paho.client.mqttv3.MqttClient) with username and password:

Version:

Paho MQTT Client: org.eclipse.paho.client.mqttv3-1.2.0.jar
Mosquitto Version: mosquitto-1.5
mosquitto-auth-plugin: compatible with 1.5

Error@Broker

1558438891: New connection from 192.168.50.128 on port 1883.
1558438891: |-- mosquitto_auth_unpwd_check(testUser)
1558438891: |-- ** checking backend sqlite
1558438891: |-- getuser(testUser) AUTHENTICATED=1 by sqlite
1558438891: New client connected from 192.168.50.128 as TestApp (c1, k60, u'testUser').
1558438891: No will message specified.
1558438891: Sending CONNACK to TestApp (0, 0)
1558438891: Received SUBSCRIBE from TestApp
1558438891:     MyTopic/# (QoS 1)
1558438891: Sending SUBACK to TestApp
1558438891: Socket error on client TestApp, disconnecting.
1558438891: |-- mosquitto_auth_acl_check(..., client id not available, testUser, MyTopic/#, MOSQ_ACL_WRITE)
1558438891: |-- aclcheck(testUser, MyTopic/#, 4) CACHEDAUTH: 17

Code Snippet:

options = new MqttConnectOptions();
//...
//...
options.setCleanSession(true);
options.setUserName(username);
options.setPassword(password.toCharArray());
//...

client = new MqttClient(clientHostname.toString(), "TestApp"); ===> OK
//...
client.subscribe(lS.getSubscriptionTopic(), 1); ===> Error
    MqttException (128)
    at org.eclipse.paho.client.mqttv3.MqttClient.subscribe(MqttClient.java:438)
    at org.eclipse.paho.client.mqttv3.MqttClient.subscribe(MqttClient.java:424)

Upvotes: 1

Views: 3458

Answers (1)

Dhruv Saraswat
Dhruv Saraswat

Reputation: 1152

I was getting the same exception when I was working with paho MQTT broker.

MqttException (128)

The issue for me was that the MQTT paho client could only subscribe to 50 subscribe topics at a time. If I tried subscribing to the 51st subscribe topic with the same MQTT client, I would get the above exception.

The solution for that was to unsubscribe from the subscribe topic after I received the response on that topic.

org.eclipse.paho.client.mqttv3.MqttClient mqttClient;

mqttClient.subscribe(String subscribeTopic);
mqttClient.publish(String publishTopic, String payload);

//Read the message published back on the subscribe topic.
//Now unsubscribe from that subscribe topic.

mqttClient.unsubscribe(String subscribeTopic);

Upvotes: 0

Related Questions