我已经在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);
线程中的异常" main" java.lang.IllegalArgumentException异常 在org.eclipse.paho.client.mqttv3.MqttClient。(MqttClient.java:170) 在mqtt_pub.Thermometer。(Thermometer.java:26) 在mqtt_pub.Thermometer.main(Thermometer.java:65)
我发现@throws IllegalArgumentException如果QoS的值不是0,1或2但是在类MemoryPersistence中他们没有提到。请帮助,提前谢谢。
答案 0 :(得分:2)
如果您查看MttqClient
的{{3}},则可以看到uuid
的长度最多只能为23个字符。看起来uuid更长:
if (clientId == null || clientId.length() == 0 || clientId.length() > 23)
{
throw new IllegalArgumentException();
}
UUID.randomUUID().toString()
返回一个长度为36 char的字符串;