【发布时间】:2015-04-10 23:37:56
【问题描述】:
为了演示 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);
线程“主”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 类中他们没有提到。请帮忙,提前谢谢。
【问题讨论】:
-
也许您使用的是相当旧版本的 paho mqtt 库 - 那么,您使用的是哪个版本?
-
我使用的是 paho 1.0.1 版本。但我在eclipse.org/paho/files/javadoc/index.html?org/eclipse/paho/… 中阅读了它的文档,可能是 mqttv3