为了演示Paho MQTT,我已经在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);
异常在线程 “主” 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)
我发现@抛出IllegalArgumentException如果QoS的值不是0,1或2,但在类MemoryPersistence中他们没有提到。请提前帮助,谢谢。
也许你正在使用一个相当老版本的paho mqtt库 - 那么,你使用的是哪个版本? – nos 2015-02-10 19:53:06
我使用了paho 1.0.1版本。但我在http://www.eclipse.org/paho/files/javadoc/index.html?org/eclipse/paho/client/mqttv3/IMqttClient.html阅读它的文档,也许它是mqttv3 – Bryan 2015-02-10 19:57:51