我已经下载了Java中的示例以演示Paho MQTT。
public class Thermometer {
public static final String BROKER_URL = "tcp://test.mosquitto.org:1883";
public static final String TOPIC = "xyz.abc";
private MqttClient client;
public Thermometer() {
try {
MemoryPersistence per = new MemoryPersistence();
String clientId = UUID.randomUUID().toString();
client = new MqttClient(BROKER_URL, clientId, per);
} catch (MqttException e) {
e.printStackTrace();
System.exit(1);
}
}
问题,当我运行它,它座落于发生client = new MqttClient(BROKER_URL, clientId, per);
与
mqtt_pub.Thermometer。(Thermometer.java:26)上org.eclipse.paho.client.mqttv3.MqttClient。(MqttClient.java:170)处的线程“ main”中的java.lang.IllegalArgumentException,位于mqtt_pub.Thermometer.main(温度计.java:65)
我发现@throws IllegalArgumentException如果QoS的值不为0、1或2,但是在MemoryPersistence类中没有提及。请帮助,提前谢谢。
如果您查看源代码,MttqClient
您会发现uuid
最多只能有23个字符的长度。看起来uuid更长:
if (clientId == null || clientId.length() == 0 || clientId.length() > 23)
{
throw new IllegalArgumentException();
}
UUID.randomUUID().toString()
返回长度为36个字符的字符串;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句