提交 c73fad22 编写于 作者: 浅梦2013's avatar 浅梦2013

去除演示中的 qos2 参数,性能损耗大避免误用。

上级 ea4cc70a
......@@ -113,10 +113,10 @@ MqttServer mqttServer = MqttServer.create()
.start();
// 发送给某个客户端
mqttServer.publish("clientId","/test/123", ByteBuffer.wrap("mica最牛皮".getBytes()), MqttQoS.EXACTLY_ONCE);
mqttServer.publish("clientId","/test/123", ByteBuffer.wrap("mica最牛皮".getBytes()));
// 发送给所有在线监听这个 topic 的客户端
mqttServer.publishAll("/test/123", ByteBuffer.wrap("mica最牛皮".getBytes()), MqttQoS.EXACTLY_ONCE);
mqttServer.publishAll("/test/123", ByteBuffer.wrap("mica最牛皮".getBytes()));
// 停止服务
mqttServer.stop();
......
......@@ -17,7 +17,6 @@
package net.dreamlu.iot.mqtt.server;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.codec.MqttQoS;
import net.dreamlu.iot.mqtt.core.server.MqttServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -53,10 +52,7 @@ public class MqttServerTest {
timer.schedule(new TimerTask() {
@Override
public void run() {
mqttServer.publishAll("/test/123", ByteBuffer.wrap("mica最牛皮".getBytes()), MqttQoS.EXACTLY_ONCE);
mqttServer.publishAll("/test/123/456", ByteBuffer.wrap("mica最牛皮".getBytes()), MqttQoS.EXACTLY_ONCE);
mqttServer.publishAll("/test/456", ByteBuffer.wrap("mica最牛皮".getBytes()), MqttQoS.EXACTLY_ONCE);
mqttServer.publishAll("/test/456/123", ByteBuffer.wrap("mica最牛皮".getBytes()), MqttQoS.EXACTLY_ONCE);
mqttServer.publishAll("/test/123", ByteBuffer.wrap("mica最牛皮".getBytes()));
}
}, 1000, 2000);
}
......
package net.dreamlu.iot.mqtt.mica.service;
import net.dreamlu.iot.mqtt.codec.MqttQoS;
import net.dreamlu.iot.mqtt.spring.server.MqttServerTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -19,7 +18,7 @@ public class ServerService {
private MqttServerTemplate server;
public boolean publish(String body) {
boolean result = server.publishAll("/test/123", ByteBuffer.wrap(body.getBytes()), MqttQoS.EXACTLY_ONCE);
boolean result = server.publishAll("/test/123", ByteBuffer.wrap(body.getBytes()));
logger.info("Mqtt publishAll result:{}", result);
return result;
}
......
package net.dreamlu.iot.mqtt.mica.task;
import net.dreamlu.iot.mqtt.codec.MqttQoS;
import net.dreamlu.iot.mqtt.core.server.MqttServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
......@@ -18,6 +17,6 @@ public class PublishAllTask {
@Scheduled(fixedDelay = 3000)
public void run() {
mqttServer.publishAll("/test/123", ByteBuffer.wrap("mica最牛皮".getBytes()), MqttQoS.EXACTLY_ONCE);
mqttServer.publishAll("/test/123", ByteBuffer.wrap("mica最牛皮".getBytes()));
}
}
......@@ -106,7 +106,7 @@ public class ServerService {
private MqttServerTemplate server;
public boolean publish(String body) {
server.publishAll("/test/123", ByteBuffer.wrap(body.getBytes()), MqttQoS.EXACTLY_ONCE);
server.publishAll("/test/123", ByteBuffer.wrap(body.getBytes()));
return true;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册