Browse Source

Fix retained message handling

release/3.x.x
Christian 6 years ago
parent
commit
abb216c055
2 changed files with 5 additions and 10 deletions
  1. +3
    -2
      Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs
  2. +2
    -8
      Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs

+ 3
- 2
Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs View File

@@ -220,7 +220,8 @@ namespace MQTTnet.Server


private MqttApplicationMessage InterceptApplicationMessage(MqttClientSession senderClientSession, MqttApplicationMessage applicationMessage) private MqttApplicationMessage InterceptApplicationMessage(MqttClientSession senderClientSession, MqttApplicationMessage applicationMessage)
{ {
if (_options.ApplicationMessageInterceptor == null)
var interceptor = _options.ApplicationMessageInterceptor;
if (interceptor == null)
{ {
return applicationMessage; return applicationMessage;
} }
@@ -229,7 +230,7 @@ namespace MQTTnet.Server
senderClientSession.ClientId, senderClientSession.ClientId,
applicationMessage); applicationMessage);


_options.ApplicationMessageInterceptor(interceptorContext);
interceptor(interceptorContext);
return interceptorContext.ApplicationMessage; return interceptorContext.ApplicationMessage;
} }




+ 2
- 8
Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs View File

@@ -4,7 +4,6 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MQTTnet.Diagnostics; using MQTTnet.Diagnostics;
using MQTTnet.Packets;


namespace MQTTnet.Server namespace MQTTnet.Server
{ {
@@ -68,7 +67,7 @@ namespace MQTTnet.Server
} }
} }


public async Task<List<MqttApplicationMessage>> GetSubscribedMessagesAsync(MqttSubscribePacket subscribePacket)
public async Task<List<MqttApplicationMessage>> GetSubscribedMessagesAsync(ICollection<TopicFilter> topicFilters)
{ {
var retainedMessages = new List<MqttApplicationMessage>(); var retainedMessages = new List<MqttApplicationMessage>();


@@ -77,13 +76,8 @@ namespace MQTTnet.Server
{ {
foreach (var retainedMessage in _retainedMessages.Values) foreach (var retainedMessage in _retainedMessages.Values)
{ {
foreach (var topicFilter in subscribePacket.TopicFilters)
foreach (var topicFilter in topicFilters)
{ {
if (retainedMessage.QualityOfServiceLevel < topicFilter.QualityOfServiceLevel)
{
continue;
}

if (!MqttTopicFilterComparer.IsMatch(retainedMessage.Topic, topicFilter.Topic)) if (!MqttTopicFilterComparer.IsMatch(retainedMessage.Topic, topicFilter.Topic))
{ {
continue; continue;


Loading…
Cancel
Save