Bläddra i källkod

Fix wrong QoS when using MqttClientMessageQueueInterceptor #978

release/3.x.x
Marc Sallin 4 år sedan
committed by Sallin Marc, I212
förälder
incheckning
7f5504b01b
2 ändrade filer med 34 tillägg och 7 borttagningar
  1. +8
    -7
      Source/MQTTnet/Server/MqttClientConnection.cs
  2. +26
    -0
      Tests/MQTTnet.Core.Tests/Server_Tests.cs

+ 8
- 7
Source/MQTTnet/Server/MqttClientConnection.cs Visa fil

@@ -397,17 +397,13 @@ namespace MQTTnet.Server
// Set the retain flag to true according to [MQTT-3.3.1-8] and [MQTT-3.3.1-9].
publishPacket.Retain = queuedApplicationMessage.IsRetainedMessage;

if (publishPacket.QualityOfServiceLevel > 0)
{
publishPacket.PacketIdentifier = _packetIdentifierProvider.GetNextPacketIdentifier();
}

if (_serverOptions.ClientMessageQueueInterceptor != null)
{
var context = new MqttClientMessageQueueInterceptorContext(
queuedApplicationMessage.SenderClientId,
ClientId,
queuedApplicationMessage.ApplicationMessage);
queuedApplicationMessage.ApplicationMessage,
queuedApplicationMessage.SubscriptionQualityOfServiceLevel);

if (_serverOptions.ClientMessageQueueInterceptor != null)
{
@@ -421,7 +417,12 @@ namespace MQTTnet.Server

publishPacket.Topic = context.ApplicationMessage.Topic;
publishPacket.Payload = context.ApplicationMessage.Payload;
publishPacket.QualityOfServiceLevel = context.ApplicationMessage.QualityOfServiceLevel;
publishPacket.QualityOfServiceLevel = context.SubscriptionQualityOfServiceLevel;
}

if (publishPacket.QualityOfServiceLevel > 0)
{
publishPacket.PacketIdentifier = _packetIdentifierProvider.GetNextPacketIdentifier();
}

if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.AtMostOnce)


+ 26
- 0
Tests/MQTTnet.Core.Tests/Server_Tests.cs Visa fil

@@ -1452,5 +1452,31 @@ namespace MQTTnet.Tests
}
}

[TestMethod]
public async Task Intercept_ClientMessageQueue_Different_QoS_Of_Subscription_And_Message()
{
const string topic = "a";

using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync(new MqttServerOptionsBuilder()
.WithClientMessageQueueInterceptor(c => { })); // Interceptor does nothing but has to be present.

bool receivedMessage = false;
var client = await testEnvironment.ConnectClientAsync();
client.UseApplicationMessageReceivedHandler(c =>
{
receivedMessage = true;
});

await client.SubscribeAsync(topic, MqttQualityOfServiceLevel.AtLeastOnce);

await client.PublishAsync(new MqttApplicationMessage{ Topic = topic, QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });

await Task.Delay(500);

Assert.IsTrue(receivedMessage);
}
}
}
}

Laddar…
Avbryt
Spara