【问题标题】:Error while subscribing with paho MQTT broker使用 paho MQTT 代理订阅时出错
【发布时间】:2019-08-21 19:37:13
【问题描述】:

我在使用用户名和密码订阅 MQTT 代理 (org.eclipse.paho.client.mqttv3.MqttClient) 时遇到错误:

版本:

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

错误@经纪人

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

代码片段:

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)

【问题讨论】:

  • 编辑问题以包含您使用的是什么版本的 mosquitto 和 mosquitto_auth_plugin?
  • 还包括 testUser 的 ACL 表中的条目。
  • 更新 mosquitto 版本信息
  • 还有问题用户的 ACL 信息?

标签: java mqtt paho


【解决方案1】:

我在使用 paho MQTT 代理时遇到了同样的异常。

MqttException (128)

我的问题是 MQTT paho 客户端一次只能订阅 50 个订阅主题。如果我尝试用同一个 MQTT 客户端订阅第 51 个订阅主题,我会得到上述异常。

解决方案是在我收到关于该主题的回复后取消订阅该主题。

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多