Updated client sessions manager to handle the delivery count for the handler correctly.

This commit is contained in:
SeppPenner
2020-06-12 20:25:51 +02:00
parent d801af5616
commit 6adf7096ec
2 changed files with 9 additions and 4 deletions
+4 -2
View File
@@ -46,17 +46,19 @@ namespace MQTTnet.Server
/// </summary> /// </summary>
public IDictionary<object, object> Items { get; } public IDictionary<object, object> Items { get; }
public void EnqueueApplicationMessage(MqttApplicationMessage applicationMessage, string senderClientId, bool isRetainedApplicationMessage) public bool EnqueueApplicationMessage(MqttApplicationMessage applicationMessage, string senderClientId, bool isRetainedApplicationMessage)
{ {
var checkSubscriptionsResult = SubscriptionsManager.CheckSubscriptions(applicationMessage.Topic, applicationMessage.QualityOfServiceLevel); var checkSubscriptionsResult = SubscriptionsManager.CheckSubscriptions(applicationMessage.Topic, applicationMessage.QualityOfServiceLevel);
if (!checkSubscriptionsResult.IsSubscribed) if (!checkSubscriptionsResult.IsSubscribed)
{ {
return; return true;
} }
_logger.Verbose("Queued application message with topic '{0}' (ClientId: {1}).", applicationMessage.Topic, ClientId); _logger.Verbose("Queued application message with topic '{0}' (ClientId: {1}).", applicationMessage.Topic, ClientId);
ApplicationMessagesQueue.Enqueue(applicationMessage, senderClientId, checkSubscriptionsResult.QualityOfServiceLevel, isRetainedApplicationMessage); ApplicationMessagesQueue.Enqueue(applicationMessage, senderClientId, checkSubscriptionsResult.QualityOfServiceLevel, isRetainedApplicationMessage);
return false;
} }
public async Task SubscribeAsync(ICollection<MqttTopicFilter> topicFilters) public async Task SubscribeAsync(ICollection<MqttTopicFilter> topicFilters)
@@ -228,12 +228,15 @@ namespace MQTTnet.Server
foreach (var clientSession in _sessions.Values) foreach (var clientSession in _sessions.Values)
{ {
clientSession.EnqueueApplicationMessage( var isSubscribed = clientSession.EnqueueApplicationMessage(
applicationMessage, applicationMessage,
sender?.ClientId, sender?.ClientId,
false); false);
deliveryCount++; if (isSubscribed)
{
deliveryCount++;
}
} }
if (deliveryCount == 0) if (deliveryCount == 0)