为了演示Paho MQTT,我下载了一个Java示例。
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);
org.eclipse.paho.client.mqttv3.MqttClient.(MqttClient.java:170) at mqtt_pub.Thermometer.(Thermometer.java:26) at mqtt_pub.Thermometer.main(Thermometer.java:65)的线程"main“java.lang.IllegalArgumentException中的异常
我发现,如果IllegalArgumentException的值不是0、1或2,而是在类MemoryPersistence中没有提到,那么@会抛出MemoryPersistence。请帮忙,谢谢。
发布于 2015-02-10 19:30:50
如果您查看源代码 of MttqClient,您可以看到uuid只能有最大23个字符。看起来uuid更长:
if (clientId == null || clientId.length() == 0 || clientId.length() > 23)
{
throw new IllegalArgumentException();
}UUID.randomUUID().toString()返回长度为36个字符的字符串;
https://stackoverflow.com/questions/28440131
复制相似问题