mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 03:24:33 +08:00
Fix handling of retained messages with QoS > 0.
This commit is contained in:
@@ -392,7 +392,7 @@ namespace MQTTnet.Server
|
||||
foreach (var retainedApplicationMessage in subscribeResult.RetainedMessages)
|
||||
{
|
||||
var publishPacket = _packetFactories.Publish.Create(retainedApplicationMessage.ApplicationMessage);
|
||||
Session.EnqueueControlPacket(new MqttPacketBusItem(publishPacket));
|
||||
Session.EnqueueDataPacket(new MqttPacketBusItem(publishPacket));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace MQTTnet.Server
|
||||
{
|
||||
readonly MqttClientSessionsManager _clientSessionsManager;
|
||||
readonly MqttPacketBus _packetBus = new MqttPacketBus();
|
||||
readonly MqttPacketIdentifierProvider _packetIdentifierProvider = new MqttPacketIdentifierProvider();
|
||||
|
||||
readonly MqttServerOptions _serverOptions;
|
||||
|
||||
@@ -100,6 +101,11 @@ namespace MQTTnet.Server
|
||||
SubscriptionsManager.Dispose();
|
||||
}
|
||||
|
||||
public void EnqueueControlPacket(MqttPacketBusItem packetBusItem)
|
||||
{
|
||||
_packetBus.EnqueueItem(packetBusItem, MqttPacketBusPartition.Control);
|
||||
}
|
||||
|
||||
public void EnqueueDataPacket(MqttPacketBusItem packetBusItem)
|
||||
{
|
||||
if (_packetBus.ItemsCount(MqttPacketBusPartition.Data) >= _serverOptions.MaxPendingMessagesPerClient)
|
||||
@@ -118,28 +124,27 @@ namespace MQTTnet.Server
|
||||
}
|
||||
|
||||
var publishPacket = (MqttPublishPacket)packetBusItem.Packet;
|
||||
|
||||
if (publishPacket.QualityOfServiceLevel > MqttQualityOfServiceLevel.AtMostOnce)
|
||||
{
|
||||
publishPacket.PacketIdentifier = _packetIdentifierProvider.GetNextPacketIdentifier();
|
||||
|
||||
_unacknowledgedPublishPackets[publishPacket.PacketIdentifier] = publishPacket;
|
||||
}
|
||||
|
||||
_packetBus.EnqueueItem(packetBusItem, MqttPacketBusPartition.Data);
|
||||
}
|
||||
|
||||
public void EnqueueControlPacket(MqttPacketBusItem packetBusItem)
|
||||
{
|
||||
_packetBus.EnqueueItem(packetBusItem, MqttPacketBusPartition.Control);
|
||||
}
|
||||
|
||||
public void EnqueueHealthPacket(MqttPacketBusItem packetBusItem)
|
||||
{
|
||||
_packetBus.EnqueueItem(packetBusItem, MqttPacketBusPartition.Health);
|
||||
}
|
||||
|
||||
|
||||
public void Recover()
|
||||
{
|
||||
// TODO: Keep the bus and only insert pending items again.
|
||||
// TODO: Check if packet identifier must be restarted or not.
|
||||
// TODO: Recover package identifier.
|
||||
_packetBus.Clear();
|
||||
|
||||
foreach (var publishPacket in _unacknowledgedPublishPackets.Values.ToList())
|
||||
|
||||
Reference in New Issue
Block a user