Files
IM-server-new/broker/src/main/java/io/moquette/spi/impl/PersistentQueueMessageSender.java
T

62 lines
2.5 KiB
Java
Raw Normal View History

2016-12-11 11:42:10 +01:00
package io.moquette.spi.impl;
import io.moquette.server.ConnectionDescriptorStore;
2016-12-11 11:42:10 +01:00
import io.moquette.spi.ClientSession;
import io.netty.handler.codec.mqtt.MqttPublishMessage;
import io.netty.handler.codec.mqtt.MqttQoS;
2016-12-11 11:42:10 +01:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static io.moquette.spi.impl.ProtocolProcessor.asStoredMessage;
import static io.netty.handler.codec.mqtt.MqttQoS.AT_MOST_ONCE;
2016-12-13 00:46:19 +01:00
class PersistentQueueMessageSender {
2016-12-11 11:42:10 +01:00
2016-12-13 00:46:19 +01:00
private static final Logger LOG = LoggerFactory.getLogger(PersistentQueueMessageSender.class);
private final ConnectionDescriptorStore connectionDescriptorStore;
2016-12-11 11:42:10 +01:00
public PersistentQueueMessageSender(ConnectionDescriptorStore connectionDescriptorStore) {
this.connectionDescriptorStore = connectionDescriptorStore;
2016-12-11 11:42:10 +01:00
}
void sendPublish(ClientSession clientsession, MqttPublishMessage pubMessage) {
2016-12-11 11:42:10 +01:00
String clientId = clientsession.clientID;
final int messageId = pubMessage.variableHeader().messageId();
final String topicName = pubMessage.variableHeader().topicName();
2016-12-11 11:42:10 +01:00
if (LOG.isDebugEnabled()) {
LOG.debug(
"Sending PUBLISH message. MessageId={}, CId={}, topic={}, qos={}, payload={}",
messageId,
clientId,
topicName,
DebugUtils.payload2Str(pubMessage.payload()));
} else {
LOG.info("Sending PUBLISH message. MessageId={}, CId={}, topic={}", messageId, clientId, topicName);
2016-12-11 11:42:10 +01:00
}
boolean messageDelivered = connectionDescriptorStore.sendMessage(pubMessage, messageId, clientId);
MqttQoS qos = pubMessage.fixedHeader().qosLevel();
if (!messageDelivered && qos != AT_MOST_ONCE && !clientsession.isCleanSession()) {
LOG.warn(
"The PUBLISH message could not be delivered. It will be stored. "
+ "MessageId = {}, CId={}, topic = {}, qos = {}, cleanSession = {}.",
messageId,
clientId,
topicName,
qos,
false);
clientsession.enqueue(asStoredMessage(pubMessage));
} else {
LOG.warn(
"The PUBLISH message could not be delivered. It will be discarded. "
+ "MessageId = {}, CId={}, topic = {}, qos = {}, cleanSession = {}.",
messageId,
clientId,
topicName,
qos,
true);
}
2016-12-11 11:42:10 +01:00
}
}