3

为了演示 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) 在 mqtt_pub.Thermometer.(Thermometer.java:26) 在 mqtt_pub.Thermometer.main(温度计.java:65)

我发现 @throws IllegalArgumentException 如果 QoS 的值不是 0、1 或 2,但在他们没有提到的 MemoryPersistence 类中。请帮忙,提前谢谢你。

4

1 回答 1

2

如果你看一下你的源代码MttqClient你会发现它的uuid长度最多只能是 23 个字符。看起来 uuid 更长:

if (clientId == null || clientId.length() == 0 || clientId.length() > 23)  
{
      throw new IllegalArgumentException();
}

UUID.randomUUID().toString()返回一个长度为 36 个字符的字符串;

于 2015-02-10T19:30:50.907 回答