|
|
|
@ -35,7 +35,6 @@ public class MqttUtil {
|
|
|
|
|
private int qos;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean publish2MQTT(String content) {
|
|
|
|
|
MqttClient client;
|
|
|
|
|
MqttDeliveryToken token;
|
|
|
|
@ -108,12 +107,14 @@ public class MqttUtil {
|
|
|
|
|
public void connectionLost(Throwable cause) {
|
|
|
|
|
log.info("connectionLost:{}", cause.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void messageArrived(String topic, MqttMessage message) {
|
|
|
|
|
log.info("topic:{} ", topic);
|
|
|
|
|
log.info("Qos:{} ", message.getQos());
|
|
|
|
|
log.info("{}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " message content接收: " + new String(message.getPayload()));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void deliveryComplete(IMqttDeliveryToken token) {
|
|
|
|
|
log.info("deliveryComplete---------{}", token.isComplete());
|
|
|
|
|
}
|
|
|
|
@ -121,7 +122,8 @@ public class MqttUtil {
|
|
|
|
|
client.connect(options);
|
|
|
|
|
client.subscribe(topic, qos);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace(); }
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|