On retained republish message adapt the QoS to the one specified during subscription (fix issue #411)

This commit is contained in:
andsel
2018-06-28 00:26:42 +02:00
parent 99226aadbd
commit 88e0ccf20e
6 changed files with 86 additions and 44 deletions
@@ -31,7 +31,7 @@ public interface IMessagesStore {
class StoredMessage implements Serializable {
private static final long serialVersionUID = 1755296138639817304L;
final MqttQoS m_qos;
private MqttQoS m_qos;
final byte[] m_payload;
final String m_topic;
private boolean m_retained;
@@ -44,6 +44,11 @@ public interface IMessagesStore {
m_topic = topic;
}
public void setQos(MqttQoS qos) {
this.m_qos = qos;
}
public MqttQoS getQos() {
return m_qos;
}
@@ -858,6 +858,14 @@ public class ProtocolProcessor {
newSubscription.getClientId(), newSubscription.getTopicFilter(), messages.size());
}
ClientSession targetSession = this.sessionsRepository.sessionForClient(newSubscription.getClientId());
// adapt the message QoS to subscriber's accepted accepted
for (IMessagesStore.StoredMessage msg : messages) {
int lowestQoS = Math.min(msg.getQos().value(), newSubscription.getRequestedQos().value());
MqttQoS qosToPublish = MqttQoS.valueOf(lowestQoS);
msg.setQos(qosToPublish);
}
this.internalRepublisher.publishRetained(targetSession, messages);
// notify the Observables