Minor, unified method
This commit is contained in:
@@ -11,6 +11,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
import static io.moquette.parser.proto.messages.AbstractMessage.QOSType.MOST_ONE;
|
||||||
|
|
||||||
class BestEffortMessageSender {
|
class BestEffortMessageSender {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BestEffortMessageSender.class);
|
private static final Logger LOG = LoggerFactory.getLogger(BestEffortMessageSender.class);
|
||||||
@@ -24,11 +26,7 @@ class BestEffortMessageSender {
|
|||||||
String clientId = clientsession.clientID;
|
String clientId = clientsession.clientID;
|
||||||
|
|
||||||
LOG.debug("publishQos0 invoked clientId <{}> on topic <{}>", clientId, topic);
|
LOG.debug("publishQos0 invoked clientId <{}> on topic <{}>", clientId, topic);
|
||||||
PublishMessage pubMessage = new PublishMessage();
|
PublishMessage pubMessage = createPublishForQos(topic, MOST_ONE, message);
|
||||||
pubMessage.setRetainFlag(false);
|
|
||||||
pubMessage.setTopicName(topic);
|
|
||||||
pubMessage.setQos(AbstractMessage.QOSType.MOST_ONE);
|
|
||||||
pubMessage.setPayload(message);
|
|
||||||
|
|
||||||
LOG.info("send publish message to <{}> on topic <{}>", clientId, topic);
|
LOG.info("send publish message to <{}> on topic <{}>", clientId, topic);
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
@@ -55,4 +53,13 @@ class BestEffortMessageSender {
|
|||||||
channel.writeAndFlush(pubMessage);
|
channel.writeAndFlush(pubMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PublishMessage createPublishForQos(String topic, AbstractMessage.QOSType qos, ByteBuffer message) {
|
||||||
|
PublishMessage pubMessage = new PublishMessage();
|
||||||
|
pubMessage.setRetainFlag(false);
|
||||||
|
pubMessage.setTopicName(topic);
|
||||||
|
pubMessage.setQos(qos);
|
||||||
|
pubMessage.setPayload(message);
|
||||||
|
return pubMessage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
import static io.moquette.spi.impl.BestEffortMessageSender.createPublishForQos;
|
||||||
|
|
||||||
class PersistentQueueMessageSender {
|
class PersistentQueueMessageSender {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(PersistentQueueMessageSender.class);
|
private static final Logger LOG = LoggerFactory.getLogger(PersistentQueueMessageSender.class);
|
||||||
@@ -25,20 +27,15 @@ class PersistentQueueMessageSender {
|
|||||||
String clientId = clientsession.clientID;
|
String clientId = clientsession.clientID;
|
||||||
LOG.debug("directSend invoked clientId <{}> on topic <{}> QoS {} retained {} messageID {}",
|
LOG.debug("directSend invoked clientId <{}> on topic <{}> QoS {} retained {} messageID {}",
|
||||||
clientId, topic, qos, false, messageID);
|
clientId, topic, qos, false, messageID);
|
||||||
PublishMessage pubMessage = new PublishMessage();
|
PublishMessage pubMessage = createPublishForQos(topic, qos, message);
|
||||||
pubMessage.setRetainFlag(false);
|
|
||||||
pubMessage.setTopicName(topic);
|
//set the PacketIdentifier only for QoS > 0
|
||||||
pubMessage.setQos(qos);
|
pubMessage.setMessageID(messageID);
|
||||||
pubMessage.setPayload(message);
|
|
||||||
|
|
||||||
LOG.info("send publish message to <{}> on topic <{}>", clientId, topic);
|
LOG.info("send publish message to <{}> on topic <{}>", clientId, topic);
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("content <{}>", DebugUtils.payload2Str(message));
|
LOG.debug("content <{}>", DebugUtils.payload2Str(message));
|
||||||
}
|
}
|
||||||
//set the PacketIdentifier only for QoS > 0
|
|
||||||
if (pubMessage.getQos() != AbstractMessage.QOSType.MOST_ONE) {
|
|
||||||
pubMessage.setMessageID(messageID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connectionDescriptors == null) {
|
if (connectionDescriptors == null) {
|
||||||
throw new RuntimeException("Internal bad error, found connectionDescriptors to null while it should be " +
|
throw new RuntimeException("Internal bad error, found connectionDescriptors to null while it should be " +
|
||||||
|
|||||||
Reference in New Issue
Block a user